Jump to content

Recommended Posts

I have some code which basically updates a section of the screen with new content.

This new content contains some javascript in it.  The javascript which is return by the ajax request does not work.  So my question, is there a way to dynamicly refresh the event handlers or something else maybe to get the javascript returned to work.

I know I could just have the javascript in the page that does the calling but there are 100's of screens it could call and therefore its not practical to do it this way.

TIA
Dale
Link to comment
https://forums.phpfreaks.com/topic/29528-loading-new-content-with-javasript-in-it/
Share on other sites

  • 1 month later...
I'm having the same problem.. i think.

I have an index page and I have links for "members" in the navbar. When a link is pressed the member info with AJAX is loading into a container on the index.php, the data in the container (member.php) contains javascript with both includes and some script in it. Javascript won't work for me either.

I even tried running a Thickbox (Cody Lindley's Thickbox) from the link but it won't run the javascript either.

???
  • 2 weeks later...
[quote]
I'm having the same issue.  Can you describe how you used the eval() statement?  Did you use it from the main page that contains the div tag where pages called by ajax are loaded, or is it in the called page?
[quote]

No, its in the calling page. Try this:
[code]
--called_page.php
<?php
  echo "alert('Whats up doc?');"
?>

--calling_page.php
<script language='javascript'>
function doSomething() {
  var ajaxResponse = getData('called_page.php');
  //this doesn't do anything because its just a string
  eval(ajaxResponse);
  //will alert "Whats up doc?"
}[/code]
Hello.

I am having the same problem. I'm unable to use the eval function to work around it though. Reason being is that I have a PHP file which queries a MySQL database and if the results meet a certain criteria then I need it to run some Javascript.

My situation is that I have a PHP file which contains AJAX code which runs another PHP file every few seconds. The PHP code that is run from AJAX queries a MySQL database and if certain results are returned I need there to be a Javascript popup window (alert()) appear. But as you're aware, AJAX doesn't evaluate Javascript. Hopefully you could help me out here, my code is as follows:

[b]index.php[/b]

[code]<html>
<head>
<script type="text/javascript">
function createRequestObject() {
  var ro;
  var browser = navigator.appName;
  if(browser == 'Microsoft Internet Explorer') {
    ro = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    ro = new XMLHttpRequest();
  }
  return ro;
}
var http = createRequestObject();

function sndReq(action) {
  http.open('get', 'reminderDisplay.php');
  http.onreadystatechange = handleResponse;
  http.send(null);
}

function handleResponse() {
  if(http.readyState == 4) {
    var response = http.responseText;
    document.getElementById('foo').innerHTML = response;
  }
}
setInterval('sndReq()', 1000);

</script>
</head>

<body>

<div id="foo">

</div>
</body>
</html>
[/code]

Then I have the code that index.php runs:

[b]reminderDisplay.php[/b]

[code]
<?php
// MySQL query here //
// Results stored here //
// If results = something then {
  Run Javascript (alert('Reminder active')) }
?>
[/code]






How could I achieve this?

Regards, Stephen




This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.