user544079
user544079

Reputation: 16629

Passing JSON string as part of url gives "Bad Request"

I am making an ajax call as

var data = {
   'name': 'John',
   'company': 'ABC',
   'salary': '$200000'
};

var Url = 'http://sample.com?result=' + JSON.stringify(data);

$.ajax({
   url: Url,
   type: 'POST',
   async: true,
   contentType: false,
   processData: false,
   cache: false,
   beforeSend: function(settings){},
   success: function(data){},
   error: function(er){}
});

I am getting a response 'Bad Request' on making the ajax call. How can I pass the JSON data in the Url. The server is not handling the formData. So that is out of the option. It needs to be passed as part of the url .

Upvotes: 0

Views: 521

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to use the data property of $.ajax(),

var data = {
   'name': 'John',
   'company': 'ABC',
   'salary': '$200000'
};

var Url = 'http://sample.com'

$.ajax({
   url: Url,
   type: 'POST',
   async: true,
   contentType: false,
   processData: false,
   cache: false,
   data: data,    //-------------Pass the data here.
   beforeSend: function(settings){},
   success: function(data){},
   error: function(er){}
});

Upvotes: 1

Related Questions