Jump to content

JavaScript functions not executing after AJAX request


robs99

Recommended Posts

Hello,

i'm trying to load a php file through AJAX which accesses a mysql db. the php file loads fine, but for some reason i can't run any javascript functions inside the file. here's the code of the php file:

 

  <?php

include ('sql.php');

if (!$_GET[start]) { $_GET[start] = 0; }

$result = mysql_query("SELECT * FROM `posts` WHERE `post_content` NOT LIKE '' AND `post_status` NOT LIKE 'draft' AND `post_status` NOT LIKE 'inherit' $sqlsearch ORDER BY `post_date` DESC , `ID` DESC LIMIT $_GET[start] , 1");

if (mysql_num_rows($result) == 0) {
echo "Sorry, no posts found. Please search for something else.<br>";
}

while($row = mysql_fetch_array($result))
{
echo "$row[post_title]<br><br>";
if ($row[genre3]) { echo "$row[genre1] - $row[genre2] - $row[genre3]"; }
elseif ($row[genre2]) { echo "$row[genre1] - $row[genre2]"; }
else { echo $row[genre1]; }

echo "<br><br><br><a href=\"javascript:runme();\">Run Me</a>";
}
?>
<script type="text/javascript">
function runme() {
alert ('test');
}
</script> 

 

any ideas why the runme function doesnt run? if i access the file directly the function works fine. stuff like <a href="javascript:alert('test');"> works aswell.

You can view the script in action here: http://it-leaked.com/v4test/

 

thanks for the help if you need any other files let me know :)

Link to comment
Share on other sites

hey,

i'm doing it manually. how exactly would the eval() work? ive tried to eval the responseText but then the loading state gets stuck at 2.

here is my js code:

 

function ShowNewReleasesAjax(start,divnumber) {
var ajaxRequest;

try{
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			alert("Your browser broke!");
			return false;
		}
	}
}
ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		var ajaxDisplay = document.getElementById("DivNewReleases" + divnumber);
		ajaxDisplay.innerHTML = ajaxRequest.responseText;
	}
		else {
		var ajaxDisplay = document.getElementById("DivNewReleases" + divnumber);
		ajaxDisplay.innerHTML = '<br><br><br><br><br><br><image src=\"php/ajax-loader.gif\">';
	}
}
ajaxRequest.open("GET", "php/releases.php?start=" + start + "&divnumber=" + divnumber, true);
ajaxRequest.send(null);
}

Link to comment
Share on other sites

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.