Whenever I make a post request from my phonegap app (using ajax in javascript) to my rails server, the post goes through successfully. However, I do not receive any response from the server which ultimately leads to failure. It's puzzling why I'm unable to retrieve the response...
Here is an example of my signup script in Javascript using ajax:
$('#sign-up-button').click(function(e) {
var str = $("#signUpForm").serialize();
$(".error").remove();
e.preventDefault();
$.ajax({url: "http://localhost:3000/api/users.json",
type: "POST",
data: str,
success: function(result, status) {
alert('success');
$.mobile.changePage( "welcome.html", { transition: "slide"} );
},
error: function(result) {
alert('error');
}
});
});
And this is my code on the Ruby on Rails side:
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
When checking in firebug, I see the message "201 Created", indicating that the user has been created. However, since I receive no response, the "alert('error')" message pops up...
Appreciate any advice and guidance on how to resolve this issue! Thanks!