Problems with my enyo app

edited May 2012 in Enyo 2
Im new to enyo programming (and web apps in general). I'm trying to get a JSON response from a website. for example, this url, give a JSON response (please be aware the demo08 part changes a lot)

https://demo08.service-now.com/incident.do?JSON&sysparm_action=getRecords&sysparm_query=active=true^priority=1

The application requires authentication, in this case username: admin, password: admin, before it responds.

Would enyo.Ajax be the right route to send the request and receive the JSON response? I have tried using ajax, but I get nothing in the variable inResponse:
requestIncident: function() {
		//var uName = this.$.userName.hasNode().value;
		//var pWord = this.$.passWord.hasNode().value;
		//alert("Username & password: "+uName+" & "+pWord);
		var request = new enyo.Ajax({url: "https://demo8.service-now.com/incident.do?JSON&sysparm_action=getRecords&sysparm_query=active=true^priority=2", handleAs: "json", username: "admin", password: "admin"});
		request.response(enyo.bind(this, "processSearchResults"));
		request.error(this, function(inSender,inValue) {
			alert("Error has occurred: "+inValue);
		});
		request.go();
	},
processSearchResults: function(inRequest, inResponse) {
		if(!inResponse) { 
			this.$.jResponse.setContent("the inResponse value is empty :(");
			return;
		}
		this.$.jResponse.setContent(inResponse.results);
		this.$.incidentList.destroyClientControls();
		enyo.forEach(inResponse.results, this.addIncident, this);
		this.$.incidentList.render();
	}
Any help would be greatly appreciated.

Comments

  • edited May 2012
    Ajax technologies in browsers have security restrictions about making requests to different servers.

    There is an overview here: http://en.wikipedia.org/wiki/Same_origin_policy

    In a nutshell, the solution is generally one of these:

    * use CORS, when the server supports it
    * use JSONP, when the server supports it
    * use a proxy on your server
Sign In or Register to comment.