Page 1 of 2

How to handle jqXHR object

Posted: Fri Aug 02, 2013 8:01 pm
by Pasteur Miranda

Hi,

Code: Select all

I'm trying to retrieve the response from a REST service, but I'm not going to define a response. Instead, I would like to read the response direct and retrieve this response. I'm using as an example, the "Build an App with Facebook API" tutorial ([url=http://docs.appery.io/tutorials/build-an-app-with-facebook-api/]http://docs.appery.io/tutorials/build...[/url] ). 
So I defined a service named RESTService (URL [url=http://www12.itrack.com.br/itrackmon/rest/login/{usuario}/{senha}]http://www12.itrack.com.br/itrackmon/...[/url] ) which has the request parameters "usuario" and "senha" . I tested this service in the "test" page and it is working. The service return one of these strings (it returns plain text, not json or xml): 
DENIED;     (returned if "usuario"  and "senha" are wrong) 
SUCCESSFUL;1ce3e47aa7a94e8ba4091b74c6aa6275   (returned if "usuario"  and "senha" are right ). 

  Following the tutorial, I defined one datasource named loginservice, and mapped the parameters "usario" and "senha" to 2 input boxes. After, I created an  event (Complete) to the loginservice datasource and added a "Run Javascript" action to it.  The javascript code associated to the action is : 

        var vars = jqXHR.responseText.split(";"); 
        alert (vars[0]); 

  Finally I defined a click event to a button and associated to this  event an action "Invoke Service" that invokes the loginservice datasource. 

  When I run the application, fill "usario" and "senha" inputs, and invoke the service clicking the button, the alert window comes empty (it had to show DENIED or SUCCESSFUL)! 
  What am I doing wrong? Is there any problem in the way I'm using the jqXHR object?  

Thank you very much in advance

How to handle jqXHR object

Posted: Fri Aug 02, 2013 8:54 pm
by maxkatz

You need to debug this more.. do an alert (or console.log(..)) on responseText.. to see what you get back. You should also fine the Error callback to see if anything is there.

http://docs.appery.io/documentation/a...


How to handle jqXHR object

Posted: Fri Aug 02, 2013 9:12 pm
by Pasteur Miranda

Hi Max,

Code: Select all

I put an alert() inside ERROR and SUCCESS events of LoginService datasource and the ERROR event is raised. I invoked the service from a click event. 

It seems very strange to me, because when I test the service in the test page it works fine. 

Thank you


How to handle jqXHR object

Posted: Fri Aug 02, 2013 9:15 pm
by maxkatz

Check the console -- to see what error you get. You might need to run it with proxy on.


How to handle jqXHR object

Posted: Fri Aug 02, 2013 9:53 pm
by Pasteur Miranda

Hi Max,

I run the application in Chrome Developer Tools and received this message in the console:

XMLHttpRequest cannot load http://www12.itrack.com.br/itrackmon/.... Origin http://appery.io is not allowed by Access-Control-Allow-Origin.

Code: Select all

Why isn't  appery.io  allowed to access the URL? 

Thank you.

How to handle jqXHR object

Posted: Fri Aug 02, 2013 10:04 pm
by maxkatz

Your app runs in the browser, not in Appery.io. It's the service that doesn't support cross-domain calls: http://docs.appery.io/documentation/a...


How to handle jqXHR object

Posted: Fri Aug 02, 2013 10:34 pm
by Pasteur Miranda

Hi Max,

Code: Select all

  I run the app with proxy on. But the application continue to raise the ERROR event of the datasource. What seems strange, is that I do not receive anymore in the console the error I reported in the previous comment, that is, the proxy solved the cross-domain problem and the console is empty. 

The application is very simple.It uses the service URL [url=http://www12.itrack.com.br/itrackmon/rest/login/xxxxy/xxx]http://www12.itrack.com.br/itrackmon/...[/url] 

I created the service using the default properties. If you test this URL, you receive the following string: DENIED; I did not define any request or response parameters. 

I created a datasource and an ERROR event with a javascript alert("ERROR"); inside it. 

Finally, I invoked the service from a button click event. 

Any Idea?

Thank you very much.


How to handle jqXHR object

Posted: Fri Aug 02, 2013 10:44 pm
by maxkatz

What is the error message that you get?


How to handle jqXHR object

Posted: Fri Aug 02, 2013 10:50 pm
by Pasteur Miranda

Hi Max,

Code: Select all

I do not receive error messages anymore. The console is empty. My service returns a plain text, as a showed in the previous comment.  

Could you try to access the service URL and create the same application as I described in the previous comment?

Thank you very much.


How to handle jqXHR object

Posted: Fri Aug 02, 2013 11:06 pm
by maxkatz

It seems to work when I invoke the service:

Image