Software Archive
Read-only legacy content

Webservice JSON in post body

Varun_R_
Beginner
430 Views

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

0 Kudos
3 Replies
Diego_Calp
Valued Contributor I
430 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

0 Kudos
Varun_R_
Beginner
430 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

 

0 Kudos
Varun_R_
Beginner
430 Views

Hi Diego,

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

Thanks

Varun

0 Kudos
Reply