开发者

jQuery AJAX request on local development environment fail

开发者 https://www.devze.com 2023-03-05 16:00 出处:网络
I\'m trying to test a jQuery/Javascript script on my local development environment. For some reason the script calls the error delegate. I\'ve attempted to make 开发者_Python百科sure I\'m not performi

I'm trying to test a jQuery/Javascript script on my local development environment. For some reason the script calls the error delegate. I've attempted to make 开发者_Python百科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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消