the*_*e_V 6 asp.net ajax service jquery
我正在尝试使用jQuery通过GET方法调用Web服务功能,但遇到了问题.这是一个Web服务代码:
[WebService(Namespace = "http://something.com/samples")]
[ScriptService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestWebService : System.Web.Services.WebService {
[WebMethod]
public string Test2()
{
string result = null;
try
{
result = "{'result':'success', 'datetime':'" + DateTime.Now.ToString() + "'";
}
catch (Exception ex)
{
result = "Something wrong happened";
}
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我调用函数的方式:
$.ajax({ type: "GET",
url: "http://localhost/testwebsite/TestWebService.asmx/Test2",
data: "{}",
contentType: "application/json",
dataType: "json",
error: function (xhr, status, error) {
alert(xhr.responseText);
},
success: function (msg) {
alert('Call was successful!');
}
});
Run Code Online (Sandbox Code Playgroud)
方法被成功调用,但结果字符串被XML标记覆盖,如下所示:
<string>
{'result':'success', 'datetime':'4/26/2010 12:11:18 PM'
</string>
Run Code Online (Sandbox Code Playgroud)
因为这个我得到一个错误(调用错误处理程序).有人知道可以做些什么吗?
为HTTP POST/GET请求启用ASP.NET ASMX Web服务
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string Test2()
{
[...]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16491 次 |
最近记录: |