...

View Full Version : Ajax Javascript Response



nsteja1
04-16-2010, 01: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:

<div>
.
.
.
</div>
<script>
onsubmit event handler.
</script>


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

Help plz!! :confused: :eek:

Gjslick
04-17-2010, 10: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.

Ex:

// (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.

-Greg



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum