Question : 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

Answer : Ajax, Jquery, YQL trying to call .net webservice

Using : var query = encodeURIComponent("select * from xml where url='" + url + "'");
We get back the xml file (xml or json format)

test page :

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
<!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 xml 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 {
			var ms = data.query.results.ArrayOfMobileSite.MobileSite;
			var table = document.createElement("table");
			table.setAttribute("border","1");
			for(var i=0;i<ms.length;i++) {
				var row = document.createElement("tr");
				for(var j in ms[i]) {
					var cell = document.createElement("td");
					cell.innerHTML = ms[i][j];
					row.appendChild(cell);
				}
				table.appendChild(row);
			}
			document.getElementById("mydiv").appendChild(table);
		}
	}
</script>
</head>
<body onload="init();"> 
<div id="mydiv"></div>
</body>
</html>
Random Solutions  
 
programming4us programming4us