0

So I have some code where I do something like:

var example = $.ajax({
                 type: "GET",
                 url: "requests.php",
                 data: {
                    requestType: "type1",
                    id_structure: 1

Is there any way of getting the "id_structure" from the example var? I mean, withouth using the success or any other callback...

Edit:Actually the ajax requests are saved into an an array instead of the variable example and sometimes I need to abort ajax requests with a given id. So I need to check if the id_structure is the same as the one I want to abort...

Ricardo Neves
  • 495
  • 3
  • 11
  • 24
  • Why would you need to get this from the `xhr` returned by `$.ajax`. You are passing this value into ajax so clearly you already have access to it. Perhaps you can describe the actual problem you are having that you think this will fix. Otherwise the answer to your question is just "no". – James Montagne Jun 09 '14 at 21:19
  • You just confused my day – GGio Jun 09 '14 at 21:23
  • I'm afraid you'll have to deal with this some other way as I don't believe this is possible. – James Montagne Jun 09 '14 at 21:27

1 Answers1

0

The xhr variable example contains the response status not the request. The Ajax request is being made right after $.ajax(..) is executed and just the response of the ajax request is stored in the xhr variable(example). so better check the value of the id_structure before making the ajax call using a if loop. something like

if(id_structure != something)
{
 var example = $.ajax({
             type: "GET",
             url: "requests.php",
             data: {
                requestType: "type1",
                id_structure: 1
sun_dare
  • 1,146
  • 2
  • 13
  • 33