B
B
BitRouter2017-05-21 06:56:31
JavaScript
BitRouter, 2017-05-21 06:56:31

AjaxSetup jQuery and DaData - how to disable global settings on suggast requests?

Good day!

-------------------------------------------------- ----------
script logic:
function int(){ //.. plugin initialization .. }
$.ajaxSetup({ //.. complete : function(){ return int(); } }) ;
Plugin initialization is launched in cases of Document Ready or ajaxSetup ..

And at the end of the development I encountered an unforeseen situation .. I

connect the jQuery plugin from DaData (suggestions) that requests data using the AJAX method ... and when the request comes from it, my script restarts it and thus throws off the result..

Otherwise: I get a response from the server, but I don’t have time to display it on the screen as ajaxSetup restarts suggestions :((

Question: how can I disable ajaxSetup for cross-domain requests?? or filter by initiators??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Pavlov, 2017-05-22
@Ifelseapps

Do not use ajaxSetup, because global settings are evil. If you need to make similar requests, wrap it in a function that, for example, will return a promise:

function _send(url, data) {
  return $.ajax({
    url: url,
    data: data
    /* Some settings */
  });
}

// пример использования
_send(url, {}).done(function () {});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question