开发者

posting form and retieving posted data in another page using jquery

I am trying to post a form to another php page. The posted data is processed in the php page and page needs to be redirected to a new url.

1) Where do i give this code for po开发者_运维百科sting the data to test.php. Do i have to call this in a function when the submit button is clicked?

 $.post("test.php", { name: "John", time: "2pm" } );

2) How do i retrieve the posted data in the test.php?

Thanks Prady


Here is working example

<script>
  var data="google";
  $.post(  
      'test.php',  
      { data: data},  
      function(response){  
        if(response.status=='success')
        window.location.href = response.url;
        else
        alert('url not retrive');
      }  
  ,json);    
</script>

test.php

  if($data="google")
  {
   $return = array('status'=>'success','url' => 'http://google.com');
   echo json_encode($return);
  }
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜