Link to home
Start Free TrialLog in
Avatar of Steve Jebson
Steve JebsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Ajax, Jquery, YQL trying to call .net webservice

Hi,

Ultimately I would like to populate a drop down list with data returned from a webservice call.

I initially tried to use jquery to call a webservice (http://www.guidelineweb.co.uk/ajax.html) but could get nothing back, it was suggested that this was due to cross-domain issues, the webservice exists on http://uat.msmsoftware.com

It was suggested that yql could be used so i created a test (http://www.guidelineweb.co.uk/csajax4.html) and the HelloWorld works, however the GetSites method returns an array of Site objects but it appears that the yql just returns a string of all the site objects. I also tried substituting the dataType: "json" with dataType: "jsonp" as i'd read in another post without any sucess, unless i needed to do something else to support that change ?

Now i'm really stuck ! and i'm also pretty in experienced with these libraries, can anyone give me some pointers please ?

thanks
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Check csajax4.js :

the format is xml :

$.getJSON("http://query.yahooapis.com/v1/public/yql?"+"q=select%20*%20from%20html%20where%20url%3D%22"+encodeURIComponent(url)+"%22&format=xml'&callback=?",

if you want a json object back, set it to json

$.getJSON("http://query.yahooapis.com/v1/public/yql?"+"q=select%20*%20from%20html%20where%20url%3D%22"+encodeURIComponent(url)+"%22&format=json'&callback=?",
Avatar of Steve Jebson

ASKER

but when i debug in ff and look at the data.results it is and array of 1 that contains all the data in the following format <body><p> ... all data ...</p></body> and that's the same if i have format=xml or format=json
remove the simple quote after json and before &callback:


$.getJSON("http://query.yahooapis.com/v1/public/yql?"+"q=select%20*%20from%20html%20where%20url%3D%22"+encodeURIComponent(url)+"%22&format=json'&callback=?",
I get sometthing with :


function doAjax(url,container){
    // if the URL starts with http
    if(url.match('^http')){
      // assemble the YQL call
      $.getJSON("http://query.yahooapis.com/v1/public/yql?"+"q=select%20*%20from%20html%20where%20url%3D%22"+encodeURIComponent(url)+"%22&format=json&callback=?",
        function(data){
          if(data.query.results.body){
//            var data = filterData(data.query.results.body.p);
            container.html(data.query.results.body.p);

Open in new window

If you want to do it with the dynamic script method, check this link : http://james.padolsey.com/javascript/using-yql-with-jsonp/
Check this :

with dynamic script, you don't worry about the cross domain limitation

check the parameter callback at the end of the script source : &callback=success
When the data is available (or an error is throw), the success function is called with the message/data
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	function init() {
		var url = "http://uat.msmsoftware.com/GemsMobileReporting/MobileReportingService.asmx/GetSites?userid=141&contractid=97&restrictbyuser=false"
		var query = encodeURIComponent("select * from html where url='" + url + "'");
		var script = document.createElement("script");
		script.setAttribute("language","javascript");
		script.setAttribute("src", "http://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&callback=success");
		document.body.appendChild(script);
	}
	function success(data) {
		if(data.error) {
			alert(data.error.description);
		}
		else {
			//alert("count of query : " + data.query.count);
			document.getElementById("mydiv").innerHTML = data.query.results.body.p;
		}
	}
</script>
</head>
<body onload="init();"> 
<div id="mydiv"></div>
</body>
</html>

Open in new window

hi leakim971,
i'm not sure i've made my point very well, it's not that i'm not getting anything back via yql, it's that it comes back as a single object whereas what the webservice is serving is an array of Sites so i was kinda expecting an array when it returns ? It may be that i'm just not getting this but does it make sense what i think i should be getting ?

Steve
Oups...

>the webservice exists on http://uat.msmsoftware.com

When I go on this page I get : You are connected to the DEFAULT Website on DEV1
Do you have a description or a main page describing the webservice ?

and for the GetSites method enter userid: 141 contractid: 97 restrictbyuser: false
just replace html by xml...

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're an absolute star !!
So all in all it was just that i was asking for html in the select that should have been xml as in that is what was being delivered. Obvious now, that's programming !   ;-)
Thanks a lot for the points! Have a nice day!