0
我寫這個java腳本來發送json對象到c#web服務。但它不工作...爲什麼? 這是我的JavaScript ..如何發送json對象到C#web服務器
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery- 1.5.1.js"></script>
<script type="text/javascript">
function BindJson() {
document.getElementById("demo").innerHTML=Date();
$.ajax({
type: "POST",
url: "Service1.asmx/SerializeJson",
data: JSON.stringify({ person:{ firstName: "Denny" }}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data2) {
alert(data2.d);
},
error: function (request, status, errorThrown) {
alert(status);
}
});
}
</script>
這是我的服務器類..
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string SerializeJson(Person person)
{
return "Success";
}
public class Person
{
public string firstName { get; set; }
}
}