A while back, Dave wrote a post on this subject. Last week, I decided to pick up where he left off.
I’ve got some web services that take parameters so I decided to try to figure out how to pass the parameters up using dojo.xhrGet. You’ll have to check out Dave’s post for the fundamentals but here’s what I did. I created a criteria object with the parameters that I needed to pass to the webservice (the vals object was returned by a call to my dojo dialog’s getValues method):
var criteria = { “projectName”:’”‘ + vals.projectName + ‘”‘, “bufferDistance”:vals.bufferDistance };
then I added the criteria to my dojo.xhrGet (note the ‘content: criteria’ part):
dojo.xhrGet({
url: 'Services/FuelsSearchService.asmx/GetByProject',
handleAs: 'json',
contentType: "application/json; charset=utf-8",
content: criteria,
load: handleFuelsResults,
error: callbackError,
timeout: 10000
});
And it works!
Well, not right away. See those funky extra quotes around the projectName value? Well it wouldn’t work until I added those. Even though you and I know that vals.projectName is a string, dojo knows it’s a string, and javascript knows it’s a string, Microsoft’s javascript deserialization stuff apparently doesn’t know that. I kept getting “Error: bad http response code:500″. But when I actually looked at the response in Firebug, it said, “Invalid JSON primitive: Cities.” Cities is the value of vals.projectName. So I added the extra quotes and voila, it works. But it’s ugly. Anybody know another way?
I noticed that your url is a local resource and not an http. Have you tried your example with your web service published to a different machine/domain? Have you tried to bind the response to a dojo grid? I’m having issues binding results that come back from services that are not local. Just wondering if you had taken the resultset to the next level by binding it for the client to view.
Comment by VBAHole22 — August 1, 2008 @ 4:12 pm
I haven’t tried a web service on a different domain. I think you’d have to use jsonp for that which dojo can do. But like I said, I haven’t tried that. I’m pretty sure Glenn (http://ruprict.wordpress.com/) had a post on that a while ago.
I have bound the results to a yui tree and a yui datatable. Kinda weird but I’m relatively new to this whole web development thing and I was having trouble with the dojo.data stuff you need to use to easily bind to a dojo grid. I’ve since gotten pretty comfortable with dojo.data and I think it would not be very difficult to bind it to a dojo grid.
What sort of issues are you having with the results?
Comment by mike — August 1, 2008 @ 6:23 pm