0

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 .

user544079
  • 16,109
  • 42
  • 115
  • 171

1 Answers1

1

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){}
});
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
  • I need to send it as part of the url only since service is reading value using Request.getParameter() – user544079 Jun 25 '14 at 05:20
  • @user544079 This might be helpful for you, http://stackoverflow.com/questions/15872658/standardized-way-to-serialize-json-to-query-string and http://stackoverflow.com/questions/3308846/serialize-object-to-query-string-in-javascript-jquery But passing JSON as a query string is a bad practice. :\ – Rajaprabhu Aravindasamy Jun 25 '14 at 05:21