我對jquery ajax數據格式有疑問。從客戶端傳輸到服務器時,用戶數據的數據類型是什麼? 。如果數據傳遞的是數據:{//用戶數據}給出500個錯誤。但是如果像數據一樣傳遞:「{}」或數據:「{}」,則結果爲成功。我是否需要在「'或」「之間包含數據?jquery ajax發佈數據查詢
$.ajax({
type: "POST",
url: "Contact.aspx/add",
dataType: "json",
data: '{ "Data": "hii" }',
contentType: "application/json; charset=utf-8",
success: function (response) {
},
error: function (msg) {
alert(msg.status);
}
});
------c#-------
[WebMethod]
public static void add(string Data)
{
}
'500'表示服務器出現錯誤,可能是服務器期待JSON格式的數據 – Tushar
在您的Web方法中使用Request.Form [「Data」]。而不是使用字符串數據參數 –