Results 1 to 6 of 6

Thread: Call AJAX anchored page from php

  1. #1
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Call AJAX anchored page from php

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.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?

    PHP Code:
    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!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The following:

    Code:
    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thanks for the quick response thetestingsite's

    this code won't work either...

    PHP Code:
    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.

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    This is my complete PHP code the tests the input from a form in my index.html:

    PHP Code:
    <?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/dynamici...jaxcontent.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!

  6. #6
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •