Ajax $ array post方法有时会导致错误

时间:2014-11-08 10:56:50

标签: javascript jquery ajax

我现在有一个很大的问题,我不得不说我没有很多AJAX经验,所以对于我希望的人来说这可能是个问题。

我有一个AJAX脚本,用于从PHP文件导入JSON数组,它可以在80%的时间内正常工作。

但有时每天1小时,$ajax部分会导致错误。

这是我的剧本:

function getData() {
    $.ajax({
        url: '/php/home.php', //Url to .php file
        data: {'data': data}, //Parameter to pass to the .php file, i.e. different query IDs, etc.. - DO NOT REMOVE!
        type: 'POST', //Set Ajax to 'POST' type
        dataType: 'json', //Tell the return data type to the JS engine
        timeout: 10000,
        error: function(xhr, status, error) { //If the query fails:
            alert('BETA - The cause of error is: ' + xhr.responseText); //v1.1 - display the cause of the error 
        },
        success: function(output) { //If query is successful:
            drawChart(output); //Call the chart drawing function, pass the Ajax result as parameter
        }
    });
}

引用的PHP文件总能正常工作 这甚至更奇怪,因为我试图找到原因,错误功能给了我以下内容:

status: error , error: empty , xhr.responsetext: empty

因为我说它通常有效,并且单独的JS文件会在同一段时间内导致错误。

我已经尝试了以下内容:

  • 尝试使用不同的浏览器;
  • 尝试在函数之前实现noconflicts();
  • 联系了我的主机,询问我是否有所限制,不是,他们也没有看到日志中的任何错误;
  • 尝试调试,它转到了错误;

您是否知道可能导致问题的原因是什么? 即使是暗示可以帮助我很多!非常感谢大家!

0 个答案:

没有答案