我有一個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驗證。我也在這個編輯中刪除了發佈的請求標題數據。
任何其他想法?
你使用的是什麼版本的jQuery? – 2013-03-20 15:56:28
使用jQuery 1.9.1 – 2013-03-20 15:56:59
那麼請求標頭和請求(表單)數據在safari和chrome之間有什麼不同?另外,出於興趣,你爲什麼不把它作爲JSON發送?您也可以使用內置在模型綁定和驗證中的ASP.NET MVC。 – Charlino 2013-03-20 18:38:48