简体   繁体   English

本地开发环境中的jQuery AJAX请求失败

[英]jQuery AJAX request on local development environment fail

I'm trying to test a jQuery/Javascript script on my local development environment. 我正在尝试在我的本地开发环境中测试jQuery / Javascript脚本。 For some reason the script calls the error delegate. 由于某种原因,脚本调用错误委托。 I've attempted to make sure I'm not performing a cross-domain request. 我试图确保我没有执行跨域请求。

    $.ajax({
            url: 'http://localhost',
            success: function(data, textStatus, jqXHR) {
                console.log('success');
                console.log(data);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(textStatus);
                console.log(errorThrown);
                console.log(jqXHR);
            }
        });
    return marker;
}

I'm running a WAMP stack. 我正在运行WAMP堆栈。 Here is my output: 这是我的输出:

error
undefined
XMLHttpRequest { mozResponseArrayBuffer=ArrayBuffer, status=0, more...}

Does anyone know what could be the issue? 有谁知道可能是什么问题?

Try replacing the absolute url: 尝试替换绝对网址:

url: 'http://localhost'

with a relative one: 和一个亲戚:

url: '/'

If this doesn't solve your problem FireBug and/or Fiddler will give you more hints about what is going on and why the AJAX request fails. 如果这不能解决您的问题, FireBug和/或Fiddler将为您提供有关正在发生的事情以及AJAX请求失败原因的更多提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM