The AJAX response returns a list of <a>
elements:
<a href="/1/">One</a>
<a href="/2/">Two</a>
<a href="/3/">Three</a>
How do I select only the first n a
elements from the response?
$.ajax({
url: '/' + page,
success: function (res) {
btn.after($('a', $(res)).slice(0,20));
}
});
That's what I'm currently trying but I'm getting a Uncaught Error: Syntax error, unrecognized expression
followed by the whole response.
By default, the JavaScript Agent limits the Ajax requests (using XHR or the Fetch API) sent for base or virtual pages. The limit is 250 requests for single-page applications (SPAs) and 50 for non-SPAs.
The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter. The type of data that you're expecting back from the server.
1. Using setInterval() It repeatedly calls the function on the given interval for stop you need to clear the interval using clearInterval() or close the window. Creating a function that calls the AJAX request and using this function in setInterval() and set Interval for 5 sec.
The parameters specifies one or more name/value pairs for the AJAX request. The data type expected of the server response. A function to run if the request fails. A Boolean value specifying whether a request is only successful if the response has changed since the last request.
The response had two closing div
elements at the end but no two openings, so I had to make one:
$.ajax({
url: '/' + page,
success: function (res) {
btn.after($('a', $($.trim('<div><div>'+res))).slice(0,20));
}
});
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