PhoneGap + Rails + Ajax + json

I’ve created an API for Rails and now I want a Web Service (in this case PhoneGap) to talk to it. How would I do that?

Follpwing some instructions to getting the API down from these links (Rails API Versioning Screencast, Building a RESTful API using Rails 3 Screencast, Implementing a Public API in Rails 3, and Consuming a Public Rails API using jQuery) I’ve had trouble getting the PhoneGap App to get a successful callback from Rails. Here’s how I figured it out and perhaps someone will come along and improve my current method.

In the PhoneGap code I have an ajax call to the public API login for authentication (note, login/create is not really a RESTful word so it’ll have to be tweaked to). I pass in the email address and the password and upon success I should receive some data back and a pop up box:

Screen Shot 2013-08-20 at 1.59.18 AM

Problem is even though I get this nice 200 OK message:

Screen Shot 2013-08-20 at 2.00.58 AM

Ajax or PhoneGap is not happy and returns an error instead of a success when I use the respond_to block:

Screen Shot 2013-08-20 at 2.18.00 AM

Not sure why that doesn’t work at the moment but what does work is the render callback:

Screen Shot 2013-08-20 at 1.54.46 AM

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s