View Full Version : Ajax Javascript Response

04-16-2010, 02:04 PM
hey guys!

i was trying out some form submit ajax code. It goes like this.

A Blank box is there. Clicking a link updates the blank box content to contain a form and a javascript. A PHP file gives the responsetext.

response text is something like this:

onsubmit event handler.

but it is not working. It is as if on submitting the onsubmit handler is not getting activated.

Help plz!! :confused: :eek:

04-17-2010, 11:03 PM
Unfortunately, the browser doesn't automatically parse and execute scripts when you add them dynamically like that.

There are a few forum posts out there about this though, try searching google for "execute script ajax" or something along those lines.

Did see one post that might be a solution though: http://www.webdeveloper.com/forum/showthread.php?p=917682. What you would do is run this guy's function with your responseText, and it would execute the code in the script tags, and return the HTML with the script tags stripped out. You would then use that return value in your innerHTML.


// (include that post's parseScript function here)

function handleResponse( ajaxObj ) {
if( ajaxObj.readyState == 4 ) {
var myDiv = document.getElementById( 'myDiv' );
myDiv.innerHTML = parseScript( ajaxObj.responseText );
Try that and let me know how it goes.