Page 1 of 1

xmlHTTPRequest does not work inside RUN JAVASCRIPT

Posted: Fri Aug 02, 2013 1:53 am
by Pasteur Miranda

Hi,

I'm trying to use REST service using xmlHTTPrequest, using the following code:

Code: Select all

 var xmlHttp = null; 

 xmlHttp = new XMLHttpRequest(); 
 xmlHttp.open( "GET", theUrl, false );  

 xmlHttp.send( null ); 
 alert(xmlHttp.responseText); 

theURL is replaced by my service's URL. This code is located inside a click event of a button (RUN JAVASCRIPT).
The problem is: I do not receive any response. Is there a better way to invoke the service using the URL?
Thank you in advance.


xmlHTTPRequest does not work inside RUN JAVASCRIPT

Posted: Fri Aug 02, 2013 2:19 am
by Illya Stepanov

Hello - please try to debug your code :: http://docs.appery.io/documentation/a...

In Developer tools - tab Network check if the requests are passing

Did you getting errors messages in console?


xmlHTTPRequest does not work inside RUN JAVASCRIPT

Posted: Fri Aug 02, 2013 6:16 am
by Maryna Brodina

Hello! You can't do codealert(xmlHttp.responseText);/code right after you sent request. You would need to add event listeners and track received data. These links should help
https://developer.mozilla.org/en-US/d...
https://developer.mozilla.org/en-US/d...
Also check jquery methods ajax, get, post
http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.post/
It's easier to work with these methods