-
Execute Javascript
I'm a bit green with this Ajax stuff, but am having a real fit trying to execute scripts in Ajax output. I've read a lot about eval and a number of other methods, but can't seem to get a working example. Below is the code I'm trying. The segment in bold is what I don't understand. I know what it is trying to do, but am not good with javascript, for instance I don't see where the function call should go. Sorry if this is a mess, I don't seek help often so don't know the typical protocol. A million thanks for any feedback!!
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('Problem creating the XMLHttpRequest object');
}
return req;
}
// Make the XMLHttpRequest object
var http = createRequestObject();
function sendRequest(type, location, target, conf, var1, var2, var3) {
targetLocation = target;
var time= new Date().getTime();
if(location == 'admingeneral'){
http.open('get', 'admin_general.php?type='+type+'&conf='+conf+'&target='+target+'&time='+time+'&var1='+var1 +'&var2='+var2+'&var3='+var3); }
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4 && http.status == 200){
// Text returned FROM the PHP script
var response = http.responseText;
if(response) {
// UPDATE ajaxTest content
document.getElementById(targetLocation).innerHTML = response;
}
}
}
function launchJavascript(responseText) {
// RegExp from prototype.sonio.net
var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)';
var match = new RegExp(ScriptFragment, 'img');
var scripts = responseText.match(match);
if(scripts) {
var js = '';
for(var s = 0; s < scripts.length; s++) {
var match = new RegExp(ScriptFragment, 'im');
js += scripts[s].match(match)[1];
}
eval(js);
}
}
Similar Threads
-
By aswhitehead in forum Web
Replies: 0
Last Post: 03-10-2007, 11:24 PM
-
Replies: 5
Last Post: 05-06-2006, 10:22 PM
-
By Michael in forum ASP.NET
Replies: 10
Last Post: 11-08-2005, 01:19 PM
-
By Ervin Rodriguez in forum Database
Replies: 1
Last Post: 10-03-2002, 02:55 PM
-
By Murray Foxcroft in forum Web
Replies: 5
Last Post: 11-02-2000, 03:42 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|