WEBサービスはこちら
public class HelloWorld : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Hello()
{
return "Hello World";
}
}
これがjavascript ajaxコードです
$(document).ready(function () {
$.ajax({
url: "Service/HelloWorld.asmx/Hello",
dataType: 'json',
type: 'POST',
cache: false,
crossDomain: true,
timeout: 15000,
success: function (rtndata) {
alert('Success : :' + rtndata);
},
error: function (xhr, errorType, exception) {
alert("Excep:: " + exception + "Status:: " + xhr.statusText);
}
});
});
取得エラー
Excep:: Invalid JSON: <?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Hello World</string>Status:: OK