PDA

View Full Version : Call AJAX anchored page from php



cyberjorge
10-13-2008, 01:34 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: Can't load it from php

I need to call an ajax page from a php file, here's a portion of the code in the php, but doesn't seem to work, any work around please?


if (($type == 'test1') && ($loc == 'test2')) {
include("javascript:showdiv('contentarea'); ajaxpage('result.html', 'contentarea');");
}

The above code in the php won't work, but works with just "index.html" in between include("index.html"). Can anyone help with this?

Thanks in advance!

thetestingsite
10-13-2008, 01:47 AM
The following:



include("javascript:showdiv('contentarea'); ajaxpage('result.html', 'contentarea');");

is invalid. You cannot use php to include just a javascript snippet; however, you could echo the js without having to use the "include", or you will have to include an html page with that javascript code on it.

Hope this helps.

cyberjorge
10-13-2008, 03:02 AM
thanks for the quick response thetestingsite's

this code won't work either...


echo "<script language=javascript>showdiv('contentarea'); ajaxpage('result.html', 'contentarea'); changeZIndex(4)</script>";

I prefer to call this AJAX page all in this php file.

I'm sorry but I'm very new in php but I have to use it though to do my search function.

thetestingsite
10-14-2008, 12:53 AM
Can you post a link to a demo page or post the full code so that we can see what it is that you are trying to accomplish and what could be causing it not to work.

cyberjorge
10-14-2008, 09:18 AM
This is my complete PHP code the tests the input from a form in my index.html:


<?PHP
if ($_POST['go']) {

$type = $_POST['prop_type'];
$loc = $_POST['location'];

if ($type == "" || $loc == "")
{
echo "<script language=javascript>alert('Invalid input!')</script>";
echo "<script language=javascript>javascript:history.go(-1)</script>";
}
else
{
if ($type == 'type1' && $loc == 'loc1'){
//javascript:showdiv... this is how i use this in my html file, in php no good just displays blank page of process.php
echo "<script language=javascript>javascript:showdiv('contentarea'); ajaxpage('categorized.html', 'contentarea'); changeZIndex(4);</script>";
}
elseif ($type == 'type2' && $loc == 'loc2')
//javascript:showdiv... this is how i use this in my html file, in php no good just displays blank page of process.php
echo "<script language=javascript>javascript:showdiv('contentarea'); ajaxpage('result2.html', 'contentarea'); changeZIndex(4);</script>";
else
echo "<script language=javascript>javascript:history.go(-1)</script>";
}
}
?>

To elaborate my problem further, all the sub pages in my site is loaded using the Dynamic Content Ajax Page script form this link...
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Now I have a a search function form the has dropdown lists that when submitted will be processed by a php file (full code above) and then show users the result from a static page. This static should be called using the ajaxpage() function that I can't achieve.

Hopefully there's a way to call this ajaxpage function from external php.

Thanks!

cyberjorge
10-15-2008, 02:40 AM
Got a solution for this, but don't know if it's the best step.

I put the whole code of my php file in the index instead.
This way I can easily call the JavaScript function, of course need to change the index.html to index.php