2013-03-20 62 views
0

我有一個MVC 4應用程序接收數據並返回一個Json字符串返回給客戶端。該代碼在Chrome,Firefox和IE中完美工作(只針對8 + ...但我已經看到它在IE7中工作)。但是,它並不適用於Windows的Safari 5.x(我沒有Mac ...所以我無法測試它)。在IE,Chrome和FF工作的jQuery ajax ...但不是Safari(使用MVC 4的服務器)

這裏是jQuery的...(使用1.9.1 ... THX添乙詹姆斯問...忘了前面提到它)

$.ajax({ 
     type: 'POST', 
     url: '@Url.Content("~/Request/ValidateApprover/")', 
     data: { 'name': input }, 
     success: function (json) { 
      //do some work here 
     }, 
     error: function() { 
      //tell the user that it failed here 
     } 
     }); 

這是我的控制器,這是獲得所謂的.. 。

[HttpPost] 
public ActionResult ValidateApprover() 
{ 
    string emailAddress = ""; 
    string name = this.Request.Form["name"]; //<--the form is blank using Safari 5 

    if (String.IsNullOrEmpty(name) || String.IsNullOrWhiteSpace(name)) 
    return Json(new { result = "blank" }, "application/json", JsonRequestBehavior.AllowGet); 

    //...keep going if you got a value other than blank 

當我嘗試使用this.Request.From["name"]看在我的控制器的結果,我很好使用Firefox,Chrome和IE瀏覽器的時候......但我得到使用Safari空白表單值。

編輯1:我寫了一個非常簡單的PHP頁面來檢查數據是否在Safari中正確傳遞。看起來它是......所以它看起來像是IIS和Safari之間的問題。

編輯2:我寫了一個非常簡單的MVC應用程序進行測試,數據在測試中出現......這讓我相信它是Safari中的某種HTML驗證。我也在這個編輯中刪除了發佈的請求標題數據。

任何其他想法?

+0

你使用的是什麼版本的jQuery? – 2013-03-20 15:56:28

+0

使用jQuery 1.9.1 – 2013-03-20 15:56:59

+0

那麼請求標頭和請求(表單)數據在safari和chrome之間有什麼不同?另外,出於興趣,你爲什麼不把它作爲JSON發送?您也可以使用內置在模型綁定和驗證中的ASP.NET MVC。 – Charlino 2013-03-20 18:38:48

回答

0

問題在於Safari處理Kerberos身份驗證,但我找到了一個解決方案。

http://forums.iis.net/t/1182376.aspx/1

上IIS該線程描述了Negotiate(即Kerberos)認證在Safari處理不當。您必須將Negotiate作爲提供者禁用。

在IIS(我使用IIS 7.5),點擊你的網站,然後Authentication(雙擊)→Windows Authentication(單次點擊)→Providers(右側)→Remove Negotiate and leave NTLM

這個固定我的所有問題蘋果瀏覽器。

0

這是我用:

功能setContent(contentfile){

if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp = new XMLHttpRequest(); 
} 
else{// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.onreadystatechange = function(){ 
    if (xmlhttp.readyState==4 && xmlhttp.status==200){ 
     //alert(xmlhttp.responseText); 
     $('#*******').html(xmlhttp.responseText); 
    } 
} 
xmlhttp.open("GET",contentfile,true); 
xmlhttp.send(); 

}

它工作在所有瀏覽器。

+0

對POST不起作用(至少......不是在我的IIS 8服務器的Safari 5中)將xmlhttp.open改爲' xmlhttp.open(「POST」,url,true);'然後運行'xmlhttp.setRequestHeader(「Content-type」,「application/x-www-form-urlencoded」);',然後使用' xmlhttp.send(data)'。工作正常,數據顯示在Chrome,FF和IE中的服務器(Request.Form)上...... Safari中沒有任何東西。 – 2013-03-20 18:14:25

0

它也適用於我..我使用IIS 6.0,我已經完成了。

作爲管理員運行 '命令提示' 然後

CD C:\ INETPUB

鎘adminScripts

CSCRIPT ADSUTIL。VBS獲取w3svc /的NTAuthenticationProviders

CSCRIPT adsutil.vbs設置W3SVC /的NTAuthenticationProviders 「NTLM」

重啓IIS。

相關問題