views:

52

answers:

2

i have this jquery function that i want to pass topic parameter to, i just dont know how to pass it lol :)).

the jquery function:

function loadPage(url)  //the function that loads pages via AJAX
{
    url=url.replace('#page','');    //strip the #page part of the hash and leave only the page number

    $('#loading').css('visibility','visible');  //show the rotating gif animation

    $.ajax({    //create an ajax request to load_page.php
        type: "POST",
        url: "load_page.php",
        data: 'page='+url,  //with the page number as a parameter
        dataType: "php",    //expect html to be returned
        success: function(msg){

            if(parseInt(msg)!=0)    //if no errors
            {
                $('#change-container').html(msg);   //load the returned html into pageContet
                $('#loading').css('visibility','hidden');   //and hide the rotating gif
            }
        }

    });

}

and this is the url:

http://localhost/final/home.php#page2&topic=jquery

when i click this link, the page load fines(using jquery), but its not passing the topic parameter!

<h3 class="timeline"><?php echo $_GET["topic"]; ?> echo</h3>

so this wnt echo, because it cnt access the topic param!! if you guys know what i mean :))

A: 

Well this should do it

loadPage('http://localhost/final/home.php#page2?topic=jquery');

If not, there may be something wrong with your code.


EDIT

Okay I think it is to do with the URL you are passing to it, try this instead

loadPage('#page2&topic=jquery');

I hope that fixes it for you.

Wolfy87
it deos not work
pingpong
I think I can see whats wrong, give me a sec
Wolfy87
^^ Okay, theres the edit, I think that should do the job...its because of the url you where passing to it did not need the prefix of localhost etc.
Wolfy87
no you got me wrong @wolfy, sorry its my fault for rephrasing the question, i dont want to pass the link to the function, basically when i click the link, it takes me to page2, but when i do a get statement its not reading topic, if you know what i mean, i will put the code up thier sorry
pingpong
I posted a new awnser because its a completely different problem, I thought editing this one would be the wrong way of doing it.
Wolfy87
+2  A: 

You are using $_GET there but the ajax is using post.

What happens when you use this instead:

<h3 class="timeline"><?php echo $_POST["topic"]; ?> echo</h3>
Wolfy87
it echos `undefined`
pingpong
What happens when you take out 'dataType: "php",'?
Wolfy87
Take a look here for future reference, the only allowed arguments in dataType are xml, html, script and json. Not php. http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests
Wolfy87
thank you very much it works, i wud never thought of that, cheers
pingpong
Not a problem, took me a while to spot it too.
Wolfy87