dhsieh12-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-05 16:03 UTC
Strange AJAX behavior with Prototype
I can''t figure why it''s doing this. I have this generated link
on a
child window which is part of a JS calendar script:
[code]
<a href="#"
onclick="window.opener.document.getElementById(''awardDateTxt14'').value=''12/13/2007'';window.opener.document.getElementById(''awardDateTxt14'').onchange();window.close();">13</
a>
[/code]
It sends back the selected value to the text box on the parent window,
however, I''ve modified it so it calls the onchange() event on that
text box also. On the parent window, the input''s onchange is calling
an AJAX function I''ve defined below:
[code]
function doSaveAwardDate(qID) {
var awardDate = $(''awardDateTxt'' + qID).value;
//Parse date string
var dateArray = awardDate.split(''/'');
//Build date string for db input, yyyy/mm/dd
var dateString = dateArray[2] + ''/'' + dateArray[0] +
''/'' +
dateArray[1];
dateString = encodeURIComponent(dateString);
var quoteID = encodeURIComponent(qID);
var awardDateURL = "AJAX_php/POST/filename.php";
var param = "quoteID=" + quoteID + "&awardDate=" +
dateString;
//Do the AJAX call to save the changes to the award date
new Ajax.Request(awardDateURL, {
method: ''post'',
parameters: param,
onComplete: function(transport) {
//Update was successful, hide the div
if(transport.responseText == "ok") {
alert(''Award date successfully saved.'');
}
else {
alert(''Error while updating award date: '' +
transport.responseText);
}
}
});
}
[/code]
If I click the link on the child window, it calls the AJAX function
fine and even does the database update on the server side script.
However, it does not return a response text (I''ve viewed the request
with Firebug, the header/response tab is empty, and the response tab
is stuck on Loading...)
If I fire the onchange() event manually by changing the text box value
on the parent window and tabbing out of it, the AJAX function works
perfectly and returns the response I was expecting. It also works
perfectly in both situations on IE 7.
Some fixed I''ve tried that worked is instead of returning a
window.close(); on the child window link, I returned false. Another is
setting up a function on the parent window that closes the child
window and calling the doSaveAwardDate() on a setTimeout of 100.
If anyone could shed some light on this issue it would be greatly
appreciated.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---