简体   繁体   中英

jQuery AJAX request on local development environment fail

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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