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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:44:18+00:00 2026-05-11T06:44:18+00:00

I have a form that makes an Ajax POST request to insert a widget

  • 0

I have a form that makes an Ajax POST request to insert a widget into my database. In the form, I have a select box where you can select from the widgets. After the db insert is made, I must update the select box. I actually just replace the entire form for now.

Because the select box has the widgets, I must have a copy of the objects in javascript. I call this var widget_objects. When the form is replaced during the update event, I print the ruby variable <%= @widget_objects %> and I can see the newly created object. However, when I try to access the javascript var ‘widget_objects’ in the onComplete event, the new object does not exist. I create the javascript widget_objects with this line of code on the page: widget_objects = <%= @widget_objects %>;

So it seems that the line of code above is not executed before Ajax request’s onComplete event. However, I thought the onComplete event occurs after the page has been loaded, and I would assume after scripts are eval’d….any ideas?

<%= submit_to_remote(                      'save_widget',                      'Save Widget & Generate Embed Code',                      {                         :url => widgets_url(:user_id => @user.id),                         :update => 'widget_form',                         :method => :POST,                         :html => {  :id => 'save_widget_button',                                      :onclick => 'this.value='Saving...'; this.disabled = 'true';',                                     :style => 'width: 220px;'                                  },                          :complete =>'                             $('save_widget_button').disabled='';                              $('save_widget_button').value='Save Widget & Generate Embed Code';                             var last_id = $j('select#widget_id').children(':last').attr('value');                             alert( widget_objects[last_id] );                             ',                         :success => 'reportMessage('success', request.headerJSON.success, 'save_widget_status'); $('band_form').reset();',                         :failure => 'reportMessage('failure', request.headerJSON.errors, 'save_widget_status');'                     }) %> 
  • 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. 2026-05-11T06:44:19+00:00Added an answer on May 11, 2026 at 6:44 am

    When dealing with these kinds of problems, use Firefox’ JS debugger (install the Firebug add-on), enable automatic breaking on exception (from the Scripts tab), and reload the page. If Firefox intercepts an exception (e.g. originating from within the response rjs) then fix the exception. You may also want to just surround your rjs and :complete code with a ‘try { … } catch(e) { alert(e) }’ JS wrapper.

    Next, use the JS debugger to set breakpoints inside prototype.js’s respondToReadyState method, where you’ll be able to inspect the rjs reply from your app and step through the evalResponse() method. You’ll narrow it down pretty quickly.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you don't specify otherwise it's all synchronous. This is… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer The problem here is that only the "best" location directive… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer The value can be retrieved from the DropDownList, because the… May 11, 2026 at 11:34 pm

Related Questions

When using jQuery 's ajax method to submit form data, what is the best
Because of strange cross domain AJAX problems, causing AJAX requests to fail when not
I'm trying to make some ajax-functionality in my web application, but I cannot get
I have a script that forces a download and I make a call to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.