ajax请求在localhost wampserver中不起作用

Rak*_*lam 2 javascript php ajax jquery wampserver

我有以下代码

$.ajax({
        url: "../profile/companyAutocomplete.php",
        type: "GET",
        data: dataQuery,
        dataType: "json",
        success: function(responseData) {
            companySelectHandler(responseData);
        }
    });
Run Code Online (Sandbox Code Playgroud)

我在生产服务器中调用,没有任何问题.但是当我在本地系统中使用它时,没有发出ajax请求.我已尝试过所有浏览器,但它仍然相同.造成这个问题的原因是什么?我需要打印相同的ajax错误消息.我怎样才能实现这一目标?

Rak*_*lam 5

谢谢你的回答.这不是因为相对URL引用.

我使用以下函数来确定导致Ajax请求失败的错误.

$(function() {
    $.ajaxSetup({
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Not connect.\n Verify Network.');
            } else if (jqXHR.status == 404) {
                alert('Requested page not found. [404]');
            } else if (jqXHR.status == 500) {
                alert('Internal Server Error [500].');
            } else if (exception === 'parsererror') {
                alert('Requested JSON parse failed.');
            } else if (exception === 'timeout') {
                alert('Time out error.');
            } else if (exception === 'abort') {
                alert('Ajax request aborted.');
            } else {
                alert('Uncaught Error.\n' + jqXHR.responseText);
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

该错误是一个解析错误,它是在浏览器在返回JSON之前尝试打印其他内容时生成的.在输出JSON之前通过使用ob_start和ob_end_clean来修复它,它通过从以下链接获取帮助来清除缓冲区" dataType:"json"将无效 "