2

I've an element <div id="search_result"></div>, and then I used $.ajax to retrieve some data (search result).

$.ajax({
  url: "url to server",
  dataType: "json",
  data: keyword,
  type: "post",
  success: function(data){
    /* load searchResult.php with data as passing parameter to searchResult.php */
    $("#search_result").load("searchResult.php");
  }
});

but I wanna load those data of search result to searchResult.php, how it's it,.? and how I access those parameter in searchResult.php,.?

thanks,.

2
  • How is the output format of "data" (the response of your ajax call) ? Commented Dec 15, 2011 at 13:29
  • the output format is json, should I decode it in searchResult.php,.? Commented Dec 16, 2011 at 2:29

3 Answers 3

1

In your JS:

// ...
dataType: "json",

// pass key/value pairs
data: {keyword: "foobar"},
type: "post",
// ...

In your PHP:

if(isset($_POST['keyword']) && !empty($_POST['keyword'])) {
    echo $_POST['keyword']; // echoes "foobar"
}
Sign up to request clarification or add additional context in comments.

Comments

1
  var value = "value of the data here";  
    $.ajax({
      url: "serchResult.php",
      data: "key="+value,
      type: "post",
      success: function(data){
            $('#search_result').html(data);
      }
    });

Comments

1
 var variable=10 ;
 $("#search_result").load("searchResult.php", {"variable": variable});

On searchResult.php :

 <?php echo $_POST['variable'];?>

Comments

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.