2
我得到了parseerror,因爲我的下面的ajax調用有什麼錯誤?將JSON數據發送到Webmethod時獲取parserror
<script type="text/javascript" src="json.js"></script>
var contact1 = {
"id":"5",
"name": "fsdfsd"
};
var jsonString = "{\"JsData\":" + JSON.stringify(contact1) + "}";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/ReceiveData",
data: jsonString,
// data: DTO,
dataType: "json",
success: function(msg) {
alert(msg);
},
error: function(response,ajaxOptions, thrownError) {
alert("error:" + ajaxOptions);
}
});
我的服務器端的WebMethod是
[System.Web.Services.WebMethod]
public static string ReceiveData(contact1 JsData)
{
//JsonTextParser parser = new JsonTextParser();
//JsonObject obj = parser.Parse(JsData);
//foreach (JsonObject field in obj as JsonObjectCollection)
//{
// string v = field.ToString();
//}
return "success";
}
public class contact1
{
public int id;
public string name;
}
奇妙的,傑出的和搖滾的.SANJIVANI你搖滾。我正在尋找這個解決方案的整個日子,你的職位幫助過我。 謝謝。 – 2011-06-30 19:20:57