amit
amit

Reputation: 10261

php POST response

I am making a POST to another php file that I want to render in the browser. the jquery post function does not redirect to another page. it expects the app-display.php file to return data to it. have a look at the code.

echo    '<div class="showcase_URL"><a class="purl" name="'.$row->num.'" href="#">PROJECT URL</a></div>';

what I have till now in javascript is:

$(".showcase_URL a").click(function() {
  //alert($(this).attr("name"));
    var number = $(this).attr("name");      
    $.post(
    "app-display.php", 
    {app: number}, 
    function(data){
        top.location.href = 'app-display.php';  
        });
});

what I have in app-display.php:

$query = 'SELECT num, title, thumb_url, url, type, cat, dated, details FROM app WHERE `num` = "$_POST[app]"';

but it is currently giving me a page without the contents of app-display.php. all the other fragments of the page are loading: header, footer etc. the PHP Response (in Firebug) I am getting is the normal html of the page.

how should i do it?

Upvotes: 1

Views: 919

Answers (3)

tadamson
tadamson

Reputation: 8851

Setting top.location.href in your callback is the problem - that's a redirect. $.post() is properly POSTing, and once that's complete it fires it's callback function, returning any results in the data parameter. By redirecting in the callback, you're throwing all that away and making a straight GET request to app-display.php.

If you actually mean for this to be an AJAX call & not pass off to a new page, change the callback function to do something with the data parameter instead of redirecting. Something like function(data) { $('#some-div').html(data); } should dump the response into some div.

Upvotes: 1

Sinan
Sinan

Reputation: 5980

Just use plain old <form action="app-display.php"> That way you won't need to get data back.

Upvotes: 1

Vasily Korolev
Vasily Korolev

Reputation: 1831

What else do you have in your PHP page except the line you've show that just defines a variable. Does it work if you just put some raw text in it, will it display? And after all I guess your query line is wrong, it should read $query = 'SELECT num, title, thumb_url, url, type, cat, dated, details FROM app WHERE num = '.$_POST["app"];

Upvotes: 0

Related Questions