简体   繁体   中英

Get dynamic AJAX URL with Jquery “ajaxSend”

If you go to this website: http://www.w3schools.com/ajax/ You wil see an example where on the click of a button an ajax call is made to this URL: /ajax/ajax_info.txt

You can see the request in console. I'm trying to get this URL with Jquery like this:

$( document ).ready(function() {

$(document).ajaxSend(function(evt, request, settings) {
  alert("Starting request at " + settings.url + ".");
});

});

The problem is that it is not alerting anything. Why is that? I'm testing this in two ways, first: implementing the jquery library and code in the console and second: scraping with PHP and injecting the code. Neither method is working. So how can I get the last URL?

The event being fired on the page you have listed is a jquery ajax event - from the jquery docs .

Description: Attach a function to be executed before an Ajax request is sent. This is an Ajax Event.

The page you are trying to test the code on is using plain ol' javascript and not jquery, therefore, the ajax event is never fired, and the ajaxSend function is never triggered.

You would need to get the data via a jquery ajax call to get the correct functionality.

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