PDA

View Full Version : eval()


Novus Mortuus
12-22-2008, 12:54 PM
Hi,

I've been using a lot of ajax on my website, so that the whole page doesn't have to load everytime someone clicks a link, or have loads of different pages, it updates with ajax [I'm using prototype].

Now for some links i just need to update a section of the site, so i was doing this:


function showContent(action, var1, var2, var3){

if(ajaxRequests <= 8){

ajaxRequests++;

new Ajax.Request('http://www.***.co.uk/scripts/mainContentScript.php',
{
method:'post',
parameters: {action: action, var1: var1, var2: var2, var3: var3},
onSuccess: function( i) {
get('centreContents').innerHTML = i.responseText;
ajaxRequests--;
},
onFailure: function(){ popUp("Oops", "Sorry but an error has occured. Please wait a few moments and then try again. [Error Code: AxRq]");
ajaxRequests--; }
});
}
else { popUp('Connection Problem', 'It seems you have too many open connections to the site, please wait a little while beore trying anything again, thank you.<br><br>Current Connections: ' + ajaxRequests); }
}


But sometimes it needs to just run a php script and then do something else like run another javascript function, so in that case i was doing:


eval(i.responseText);


In place of the bolded part in the function above.

However i have realised that due to certain aspects of the site i need to have them all as:


eval(i.responseText);


So that i can run functions and/or redirect the page on certain errors/occasions, etc...

And i previously tried putting something like:

<script type="text/javascript">
myfunction();
</script>

Into the file that was being included when i was doing the InnerHTML method, but that didn't work.

So how can i do the same updating of sections of the site using eval() instead?

I have tried something like this [In the php script]:

...blah

if(...blah)
{
?>
get('centreContents').innerHTML = '<?php require_once('path/to/file.inc.php'); ?>';
<?php
}

..blah


But that just breaks the function and never reaches the onSuccess stage.

Hopefully i explained that well enough.

Thanks.