开发者

Send JSON data though Jquery-Ajax to Rails3 server(heroku): data successfully saved but get error in return

here a strange problem:

Server: simple Rails3 app that record User send by client form Client: a simple form html-js using Jquery-Ajax (1.5) to send User information(name,email)

  1. When I test on my computer (Server and Client are local) The User is correctly saved by the Rails app And the code returned to my html-js client is OK (200)

  2. When I push the server code to Heroku I use the client code locally from my computer The User is correctly saved by the Heroku Rails app (yes, Access-Control-Allow-Origin seems to work!!!)

BUT my only issue is that on my client side the ajax error is raised, I cannot get the statusCode returned even the xhr.statusText is empty

AGAIN THE DATA IS PROPERLY SEND AND SAVED ON THE SERVER but I cannot see why my client raise an error.

Below my Client code, it raise non of the statusCode listed and the xhr.statusText is empty too.

  $.ajax({
                type: "POST",
                url : "http://myapp.heroku.com/users",
                cache: f开发者_运维问答alse,
                data: formData,
                 statusCode: {
                        500:function() { alert("500"); },
                        501:function() { alert("501"); },
                        502:function() { alert("502"); },
                        503:function() { alert("503"); },
                        404:function() { alert("404"); },
                        403:function() { alert("403"); },
                        402:function() { alert("402"); },
                        401:function() { alert("401"); },
                        400:function() { alert("400"); },
                        304:function() { alert("304"); },
                        303:function() { alert("303"); },
                        302:function() { alert("302"); },
                        301:function() { alert("301"); },
                        200:function() { alert("200"); },
                        201:function() { alert("201"); },
                        202:function() { alert("202"); }
                },
                success: onSuccess,
                error: function(xhr){
                    alert("The error code is: "+xhr.statusText);
                }
            });

Here the server:

# POST /users
# POST /users.xml
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.xml  { render :xml => @user, :status => :created, :location => @user }
    format.json { render :json => @user }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
  end
end
end

I wonder if I have to modify the server code? But it works when I run it locally... Thanks for your help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜