Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have some code that work, but I need to add some variable to the data sent by ajax.
I know, I can put this variable in the array sended, but it's no good for me.
I want to add +'&count='+'second'

Maybe I can send second array, but how?

var arr = new Array(1,2,3,4);
$.ajax({
    type: 'POST',
    url: baseUrl + "search/simple_filter",
    data: {arr: arr}+'&count='+'second',
    success: function (data) {
        if (!data) console.log(data);
    }
});
share|improve this question

4 Answers 4

up vote 0 down vote accepted
var arr = new Array(1,2,3,4);
             $.ajax({
             type: 'POST',
             url: baseUrl + "search/simple_filter",
             data: {'arr': arr, 'count': second},
             success: function (data) {
             if (!data) 
             console.log(data);
             }
             });
share|improve this answer

Expand your base object, like so:

  data: {arr: arr, count : 'second'}
share|improve this answer

To add a query string parameter in a POST request you would add it to the URL:

url: baseUrl + "search/simple_filter?count=" + second,
data: { arr: arr },

I assume that you want to use the value of the variable second, not the string "second".

If you want to add the parameter in the POST data, and not as a query string parameter, you would add it to the object for the data property:

url: baseUrl + "search/simple_filter",
data: { arr: arr, count: second },
share|improve this answer

You should add that to the POST URL and not the body:

 var arr = new Array(1,2,3,4);
     $.ajax({
          type: 'POST',
          url: baseUrl + "search/simple_filter"+'&count='+'second',
          data: {arr: arr},
          success: function (data) {
             if (!data) 
              console.log(data);
         }
      });
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.