Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .ajax() local testing

I've got a little .ajax function which trying to load some content after document is ready.

$(document).ready(function(){
$.ajax({
        url: 'php/accounts-blocks.php',
        cache: false,
        beforeSend: function() { $('#accounts-blocks').html('Please wait...'); },
        success: function(html) { $('#accounts-blocks').html(html); }
        });
});

However, when I'm trying to test this page locally (just on my PC), ajax shows up only "Please wait" message like forever, and doesn't load any content. Should I install local hosting or something like that in order to test AJAX functionality, or is it something wrong with script?

like image 712
Dazvolt Avatar asked Apr 14 '14 09:04

Dazvolt


People also ask

Does AJAX work locally?

Ajax call works fine locally, but not from the server when using FF.

How do I know if Ajax is working?

Try the following steps: Open developer console by pressing CTRL + SHIFT + I and go to Network tab. Click on XHR tab( uncheck all other tab to see only ajax) and select URL you want to check. Then You can inspect Header, Cookies, Response etc from respective tab.

Can we use Ajax without server?

AJAX is needed to make calls to the server using JavaScript. You cannot execute something in a back-end language alone without reloading the page.

How does Ajax work in jQuery?

What About jQuery and AJAX? jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!


1 Answers

Ajax (XHR) will not work in some browsers (there are exceptions such as Firefox) when running the script locally without having a local web server installed. Chrome is an example that will not allow it.

Use a browser with less strict security, or install a local HTTP server.

like image 54
MrCode Avatar answered Oct 03 '22 23:10

MrCode