Ajax调用不会返回正确的字符串结果
我的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) { } }); }
我的后端function被调用
[WebMethod] public static string MyFunction1() { try { if (true) { return "test"; } } catch(Exception ex) { return ex.Message; } }
你的代码在我的机器上工作正常。你可能忘了通过Jquery中的文档加载来调用它。 我的代码
和我的代码在文件后面
[WebMethod] public static string MyFunction1(string parameter) { //try //{ // if (true) // { // return "test"; // } //} //catch (Exception ex) //{ // return ex.Message; //} return parameter; }