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 :))

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

4 Comments

What happens when you take out 'dataType: "php",'?
Take a look here for future reference, the only allowed arguments in dataType are xml, html, script and json. Not php. docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests
thank you very much it works, i wud never thought of that, cheers
Not a problem, took me a while to spot it too.
0

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.

3 Comments

^^ 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.
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
I posted a new awnser because its a completely different problem, I thought editing this one would be the wrong way of doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.