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>

 

Link to comment
Share on other sites

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>"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>"

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.