Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
Contributor
Kanduc
Posts: 13
Registered: ‎02-25-2013
My Carrier: Developer

POST Method in Blackberry

Hi, I want to consume a web service using ajax. I need to use a post method but when I do it, the web services doesn't  receive the params that i'm sending. 

My code is:

 

$.ajax({
	type : "POST",
	url : url,
	data : "{id_user='"+id+"',edad='22',ciudad='Lima',sexo='ss',token='"+accessToken+"'}",
      contentType : "application/json; charset=utf-8",
	dataType : "json",
	success : function(data) {
		alert("success");
}, error : function (xhr) { if (xhr.status == 400) console.log("400 "+xhr.responseText, xhr.status); else console.log(xhr.responseText, xhr.status); } });

 

I also tried jsonp but i couldn't make a post method with it.  

 

Anyone knows how can i send a json post or how you do a post method in webworks???

Please!!!!

Please use plain text.
Developer
peardox
Posts: 734
Registered: ‎03-20-2011
My Carrier: 3, Orange, Vodafone

Re: POST Method in Blackberry

This bit is all wrong...

 

data : "{id_user='"+id+"',edad='22',ciudad='Lima',sexo='ss',token='"+accessToken+"'}",

 

You're sending a string

 

What you want is...

 

data : { id_user : id, edad : 22, ciudad : 'Lima', sexo : 'ss', token : accessToken },

 

 




Click the like button if you find my posts useful!
Please use plain text.
New Contributor
fmontanez
Posts: 5
Registered: ‎02-27-2013
My Carrier: ATT

Re: POST Method in Blackberry

[ Edited ]

Assuming you're using jQuery for the ajax call:


var url = "your webservices endpoint";
var data = ({id_user: id, edad: 22, ciudad:"Lima", sexo: "ss", token: accessToken});

$.ajax({
type : "POST",
url : url,
data : $.params(data),
dataType : "json",
success : function(data) {
alert("success");

},
error : function (err) {
console.log(JSON.stringify(err));
}
});
Please use plain text.