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 9149509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:29:12+00:00 2026-06-17T11:29:12+00:00

I’m trying to submit a form via ajax and include some variables that i’m

  • 0

I’m trying to submit a form via ajax and include some variables that i’m setting via jquery.

/views/applications/_form.html.erb

<%= form_for(@application, :html => {:class => "organizer"}, :remote => true) do |f| %>
  // fields in here
<% end %>

/controllers/applications_controller.rb

  # PUT /applications/1
  # PUT /applications/1.json
  def update
    @application = Application.find(params[:id])
    p params[:xposition]     # these get set in jquery
    p params[:application]   # these get set in jquery
    respond_to do |format|
      if @application.update_attributes(params[:application])
        @curr_app = ApplicationField.last

        format.html { redirect_to @application, notice: 'Application was successfully updated.' }
        format.json { head :no_content }
        format.js { render action: "update" }
      else
        format.html { render action: "edit" }
        format.json { render json: @application.errors, status: :unprocessable_entity }
        format.js { render action: "update" }
      end
    end
  end

/assets/javascripts/applications.js

$('.organizer').submit(function() {

        var dataToSubmit = $(this).serialize();
        var field_values = [];
        var x_values = [];
        var y_values = [];

        // i add values to the arrays above here

        for(i = 0; i < field_values.length; ++i) {
            dataToSubmit += "&field_name="+field_values[i]+"&xposition="+x_values[i]+"&yposition="+y_values[i];
        }

        $.post($(this).attr('action'), dataToSubmit);   
    });

With my current code, when the form is submitted, it goes directly to the controller, and then the $.post call in my jquery code calls the same controller and passes xpostion and yposition in the data of the $.post call (which is what i want).

How can i make it so only my form doesn’t get submitted twice – once by hitting the controller as soon as the submit button is clicked and once from my $.post call?

I thought :remote => true makes it so the form wouldn’t call the controller directly?

EDIT

If :remote => true sends an ajax request without me having to use jquery’s $.post method to send the ajax request manually, how can i send extra variables along with the ajax request that automatically gets made by using :remote => true?

EDIT

Here’s a snippet from my server log

Started PUT "/applications/3" for 127.0.0.1 at 2013-01-18 00:06:19 -0600
Processing by ApplicationsController#update as */*
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"3LOzuiL/PU6HypJ4OeN5H9yrX3Xyk0VT6XpcFYd1wY0=", "application"=>{"application_field_attributes"=>{"0"=>{"id"=>"8"}, "1"=>{"id"=>"9"}}}, "field_name"=>"aaa", "xposition"=>"0", "yposition"=>"0", "id"=>"3"}
  Account Load (0.3ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = 'localhost' LIMIT 1
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Application Load (0.4ms)  SELECT `applications`.* FROM `applications` WHERE `applications`.`id` = 3 LIMIT 1


Started PUT "/applications/3" for 127.0.0.1 at 2013-01-18 00:06:19 -0600
Processing by ApplicationsController#update as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"3LOzuiL/PU6HypJ4OeN5H9yrX3Xyk0VT6XpcFYd1wY0=", "application"=>{"application_field_attributes"=>{"0"=>{"id"=>"8"}, "1"=>{"id"=>"9"}}}, "commit"=>"Submit", "id"=>"3"}
  Account Load (0.3ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = 'localhost' LIMIT 1
  User Load (0.3ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Application Load (0.4ms)  SELECT `applications`.* FROM `applications` WHERE `applications`.`id` = 3 LIMIT 1
  • 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-17T11:29:13+00:00Added an answer on June 17, 2026 at 11:29 am

    You can try to stop all handlers except yours. Try this:

    $('.organizer').submit(function(e) {
      e.preventDefault(); // stops default behavior
      e.stopPropagation(); // prevents event bubbling
      // you code
      return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.