我编写了这个 java 脚本来将 json 对象发送到 c# web 服务。但它不起作用..为什么会这样?这是我的javascript..
<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; }
}
}