【发布时间】:2016-04-12 10:18:39
【问题描述】:
我的 ajax 调用。我没有得到所需的字符串响应。任何人都可以在这方面帮助我。提前致谢。
function Function1() {
alert("In Ajax Call");
$.ajax({
type: "POST",
url: "abc.aspx/MyFunction1",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (res) {
$('#regularticker').html(res.d);
//$('#futureticker').html(res.d);
var d = new Date(); // for now
$('#updateTime').html("Update at " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds());
//alert(res.d.toString());
alert(res);
alert(res.d);
},
error: function (res) {
}
});
}
我的后端函数调用
[WebMethod]
public static string MyFunction1()
{
try
{
if (true)
{
return "test";
}
}
catch(Exception ex)
{
return ex.Message;
}
}
【问题讨论】:
-
你得到什么回应?
-
您将 dataType 设置为“json”,但未返回 json 格式的内容。您应该在返回之前尝试将字符串编码为 json 格式。也许它可以解决您的问题。