Keertan
Keertan

Reputation: 113

simple ajax call , no syntax errors. still not working

This is the file which sends ajax request.

 function ju(id)
  {
     alert("into");
     $.ajax({
     type:'POST',
     url: "trial2.php",
     data: { flag1: id},
     success: function(result) {
         alert(result);
       },
     complete:function(){
        alert("over");
        }
    });
     }  


     ju("yoyo::");

     </script>

the trial2.php is this. simply returning what ever it received.

    session_start();

     $resultstring = "yoyo :: " . $_POST['flag1'];

    echo $resultstring;

?>

but only the "into" alert is coming. after this the page just stops working. no alerts nothing. whats wrong in this?? i have done a bit of ajax things in past, but never came accross this.

Upvotes: 0

Views: 60

Answers (2)

Drop Shadow
Drop Shadow

Reputation: 808

You send an array to your php code as data , so you have to write

$data =  $_POST['data'];

// $data is an array contain your flag1 .

Upvotes: 0

JoeyZero
JoeyZero

Reputation: 575

Maybe try adding an error callback to the ajax call to help narrow down the problem.

function ju(id)
{
   console.debug("into");
   $.ajax({
     type:"POST",
     url: "trial2.php",
     data: { flag1: id},
     success: function(result) {
       console.debug(result);
     },
     complete:function(){
       console.debug("over");
     },
     error: function(xhr, error){
       console.debug(xhr); 
       console.debug(error);
     }
   });
}  

Upvotes: 0

Related Questions