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?
Ajax call works fine locally, but not from the server when using FF.
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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With