SGr33n wrote:
> Hi ppl,
> 
> I'm using Ajax.Request to submit a form and insert a new record in a
> mysql database with asp.
> 
> Now the problem:
> 
> After the insertion of the new record I've the new record id in an asp
> variable, and i would update an input field on the submitting form with
> this value (so if i submit again the for i can update the already
> inserted record an not insert another new record).
> 
> Is there anyway to do this without reloading the page ?

Sure is. After the request has created the record and has the new id, send that
id back to the client in your response. I use JSON for this kind of thing and
put it in an X-JSON HTTP header which prototype will automatically convert into
a JS object for you. Something like this:

# response header
X-JSON: { 'success': 1, 'id': 254 }

# JS code
new Ajax.Request(
  url,
  {
    onComplete: function(response, json) {
      $('my_form_input').value = json.id;
    }
  }
);

Of course, if JSON doesn't float your boat and you want something slower, you
can use XML as well.

-- 
Michael Peters
Developer
Plus Three, LP


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to