jquery ajax 帖子返回404 Not Found in Firebug ...我有什么遗漏吗?
编辑:这是以前工作的,突然停止工作 routes.rb
#invites
match '/invites/request' => 'invites#request_invite'
邀请控制器.rb
class InvitesController < ApplicationController
def request_invite
if !request.xhr?
render_404
return
end
email_exists = Invite.where(:email => params[:invite][:email]).exists?
if email_exists
@return = { :error => false, :response => "<div class=\"success\">Thank you!</div>" }
else
@invitation = Invite.new(params[:invite])
if @invitation.save
@return = { :error => false, :response => "<div class=\"success\">Thank you!</div>" }
else
error_message = '<div class="error_message">' + @invitation.errors.full_messages.map {|error| "<p>#{error}</p>"}.join + "</div>"
@return = { :error => true, :response => error_message }
end
end
render :json => ActiveSupport::JSON.encode( @return )
end
end
邀请.rb
class Invite < ActiveRecord::Base
validates :email, :presence => true, :uniqueness => true
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
end
javascript:
//post ajax
jQuery.fn.postAjax = function(success_callback) {
this.submit(function() {
$.post(this.action, $(this).serialize(), success_callback);
return false;
})
return this;
};
$(document).ready(function() {
$("#invites_form").postAjax(function(data){
if(data.error == true){
popup.init({
title : "Please fix the following errors:",
body : data.response
});
}
});
});