Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Varun_R_
Beginner
81 Views

Webservice JSON in post body

Hi,

  I am trying to call the post method of a Nodejs webservice which expects a json object in the body.

How would I do this with XDK & IODOCS?

Thanks

Varun

Tags (2)
0 Kudos
3 Replies
Diego_Calp
Valued Contributor I
81 Views

Hi Varun,

You may use jquery ajax, something like this:

	$.ajax({
		type:'POST', 
		url: 'http://localhost:3000/endpoint',
		data: '{"email":"'+mail+'", "password":"'+pass+'"}',
		dataType: "json",
		success: function (response) {
                   //use response on success
                   console.log('success');
		},
		error: function (response) {
		   console.log('error');
		}
	});	

Regards

Diego

Varun_R_
Beginner
81 Views

Hi Diego, 

  Thanks for the reply

I modified the iodocs js file that exports the webservice to this

return $.ajax({
      url: url,
      type: 'POST',
      data:data,
       dataType: "json"
      });

The service isnt getting the json data

Thanks

Varun

 

Varun_R_
Beginner
81 Views

Hi Diego,

  Thanks. I got it working after making a few modification to the code that you suggested

Thanks

Varun

Reply