Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:10:38+00:00 2026-06-17T09:10:38+00:00

I have a form which submit a form via AJAX with :remote => true.

  • 0

I have a form which submit a form via AJAX with :remote => true. Looking at the server log and FireBug, I get the response 200 OK and it returns JSON in the form of:

{ "email": "test@test.com"}

then I have these two handlers:

$('#new_invitation').bind("ajax:success", function(event, data, status, xhr) {
    alert('test');
});

$('#new_invitation').bind("ajax:error", function() {
    alert('error');
});

and even if I get back a 200OK, it is the error handler that fires. The only time I managed to make the success handler work was when I send a empty response with 200 in the header.

I can’t figure out why this isnt working :-S

EDIT 1————
After doing these changes:

$('#new_invitation').bind("ajaxSuccess", function(event, data, status, xhr) {
    alert('test');
});

$('#new_invitation').bind("ajaxError", function(jqXHR, textStatus, errorThrown) {
alert('error');
    console.log(jqXHR.responseText);
    console.log(textStatus.responseText);
    console.log(errorThrown.responseText);
});

I am still getting the same error. The log stuff gives me:

undefined
my_email@test.com
undefined

Here is the code for the form (standard Rails stuff):

<%= form_for @shoot.invitations.new, :url=>shoot_invitations_path(@shoot), :remote => true, :html => {:class => 'form-inline'} do |f| %>
    <%= f.text_field :email, :'placeholder' => 'ex: test@test.com' %>
    <%= f.text_field :role, :'placeholder' => 'ex: Photographer' %>
    <%= f.submit "Invite", :class => 'btn btn-success' %>
<% end %>

EDIT 2 ———

I did a few changes and now it seems my error is a parse error. I dont understand because this is the JSON I am getting back from the server (data.responseText), which seems all good:

{"email":"zxxczxc@test.com"}

ANSWER ———
I managed to have everything work when I put :’data-type’ => :json in the form options. I tried this before and it did not work because I put it in the form_tag options and not the html options…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:10:38+00:00Added an answer on June 17, 2026 at 9:10 am

    If the server returns something that isn’t valid JSON, such as a single space, jQuery will generate a parse error and consider it a failed request even if the status code is 200.

    As of jQuery 1.9 a completely empty response is considered a failed request when the type is set to JSON since an empty string is invalid JSON. See http://jquery.com/upgrade-guide/1.9/#jquery-ajax-returning-a-json-result-of-an-empty-string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form in my application which I need to submit via Ajax
I have a form which on submit I want to run a script via
I have the HTML form which do prior upload of files via AJAX. So
I have a Drupal 7 form which I'm allowing the user to submit via
I have a form which I call via AJAX (for use on a CMS)
I'm trying to get a nested form to submit via AJAX, but I can't
I have a form which is submitted via ajax triggered by an image click,
I have a form which users must fill out and submit. The controller action
I have a form which I want to submit upon button click which is
I have a asp.net web form which will submit information to come as emails.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.