【问题标题】:function does not call other function函数不调用其他函数
【发布时间】:2014-04-09 04:07:32
【问题描述】:

我有一个函数在成功时调用另一个函数。如您所见,我使用了警报,它上升到警报“2”。

按 F12 时出现 500 服务器错误,但我也可以看到我的 web 服务确实可以工作,因为我看到它正确地以 XML 格式提取所有数据。我的data: param 或查询字符串也得到了正确的值。

JavaScript:

function ContactView()
{
    alert("1")
    var txtSearchbox = $("#searchTextField").val();
$.ajax({
        type: "GET",
        data: param = "searchField="+txtSearchbox+"&office="+localStorage.getItem("office")+"&person="+localStorage.getItem("person")+"&user="+localStorage.getItem("user")+"&organization="+localStorage.getItem("organization"),
        contentType: "application/json; charset=utf-8",
        url: "http://msw-wsdl.company.net/mobile.asmx/ContactGet",
        dataType: "json",
        success: successContact,
        failure: function (msg) {
            console.log(msg);
        }
    });
    alert("2")   /*this is the last alert that pop's up, nothing further*/
}
/*wsdl call succeed*/
function successContact(data) {
    alert("3")
    $("#lstView_contacts").kendoMobileListView({
        dataSource: JSON.parse(data.d),
        template: $("#lstView_contact_Template").html(),
        endlessScroll: true,
        scrollThreshold: 8
    });
    window.location = "#contactsview";
}

为什么没有调用成功回调successContact - 有什么想法吗?

【问题讨论】:

  • 没有failure 选项,因此由于相同的来源策略而失败,您没有在控制台中收到“解析错误”消息,请更改它改为error
  • @adeneo:我得到了更好的错误响应 - {"readyState":4,"responseText":"{\"Message\":\"There was an error processing the request.\",\"StackTrace\":\"\",\"ExceptionType\":\"\"}","status":500,"statusText":"Internal Server Error"}
  • 在纠正 500 错误之前,您永远不会成功。检查您发送到服务器的数据,确保其格式正确,以便在服务器端正确使用,而不是产生错误。
  • 你从哪里得到错误信息?

标签: javascript jquery


【解决方案1】:

函数successContact 只有在成功 时才会被调用,错误 500 表示它不成功。 error 方法将被调用,而不是在您的情况下定义。

【讨论】:

  • 如果您使用cross-domain 请求或JSONP,那么error 方法将不会被调用。你试过jQuery ajax的donefailalways方法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-22
  • 2016-05-27
  • 2013-10-10
  • 2018-06-09
  • 1970-01-01
  • 2021-02-26
相关资源
最近更新 更多