Nalik
Nalik

Reputation: 21

Sending variable with ajax

I'm having some troubles trying to send an id through ajax script, I'm trying to create an address book, when you select a contact it load all his information in another page and the ajax script load this page inside the main. Everything is working except to send the ID of the contact. There's a bit of the code :

 $.ajax({
         url: "select.php",
         dataType: "html",
         data: {id: id},
         success: function(Result) {
         $('#result').html(Result);
         }
        });

PHP

$id = $_POST['id'];
echo $id;
$sql = "SELECT * FROM ca11 WHERE contact_id= $id";

does anyone have an idea ?

Upvotes: 2

Views: 57

Answers (1)

Ashok
Ashok

Reputation: 184

you need to add which type of request you are making, as your question, you can call post request as below

$.ajax({
  type: "POST",
  url: "select.php",
  dataType: "html",
  data: {id: id},
  success: function(Result) {
         $('#result').html(Result);
     }
});

For more information you can refer this link http://api.jquery.com/jQuery.post/

Upvotes: 1

Related Questions