Jump to content

Problem with ajax, php and javascript link


Lassie

Recommended Posts

I am trying to use a script to dynamically fetch pages of html into a web page from a database, ajax style.

The script requires the php to 'echo' the javascript. at this point in the script it literally outputs to the browser.

Is what I am attempting possible and/or have I got the snytax wrong.

I have replaced the js script references with xxxx  as I believe the post won’t be accepted otherwise

The relevant part of the code is


<body>
<a href="xxxxx :mypages.refresh(myajaxbook)"><img src="BookJacket95x141.gif"></img></a>

<div id="paginate-top"> </div>

<div id="pcontent"> </div>

<div id="paginate-bottom"> </div>

<?php


//include db_fns
include_once('db_fns.php');
include('mysql_connect.php');
//get product_id
$product_id=13;
//connect to db
$connection=db_connect();
$query="SELECT p1,p2,p3 from ajax WHERE product_id='$product_id'";
$result = mysql_query($query) or die ("Sorry, unable to execute $sql: " . mysql_error()); // execute the query
$result = mysql_query($query);
$num_rows=mysql_num_rows($result);

$idarray=array();


for( $i=0; $i<$num_rows; $i++) 
{
	$row=mysql_fetch_row($result);	
 	array_push($idarray, array($row[0],$row[1],$row[2]));
}
//code out puts after this line
echo "<xxxxx ='xxxxx’>"; //Dynamically output JavaScript opening tag
echo "var mysettings={}\n"; //Dynamically output javascript variable
echo "mysettings.page=[" . implode(",", $idarray) . "]\n";
echo "mysettings.selectedpage=0\n";


echo "xxxx\n"; //Dynamically output JavaScript closing tag

?>
<xxxe=xxxxt">
var mypages=new ajaxpageclass.bindpages(myajaxbook, "pcontent", ["paginate-top", "paginate-bottom"])
</script>
</body>
</html>

 

Thanks.

I have tried to incorporate php variables into an ahref tag but get parse errors.

This is an example that gives parse errors. Can you help please.

?>
<a href="xxxx:ajaxpage('<?php ./$p1?>', 'contentarea');"onmouseover="Tip('View Synopsis')"><img src=<?php './images/{$book['pix']}'?> border='0' width='80' height='100'/></a>"

That PHP doesnt exist.  You have an opening tag:

 

<?php

 

and a closing tag:

 

./$p1?>

 

That closing tag doesnt exist, and even if you were to separate it into this:

 

./$p1 ?>

 

Its still not any php that I have seen.

 

You can include php variables in javascript, but it has to be valid php to work.

Ok Taking your comments into account I have modified the tag thus.

The ./$p1 is a var holding location of page to be pulled into the content area div.

 

 

?>
<a href=":ajaxpage('<?php './$p1'?>',' 'contentarea');"onmouseover="Tip('View Synopsis')"><img src=<?php './images/{$book['pix']}'?> border='0' width='80' height='100'/></a>"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.