nagaxe
nagaxe

Reputation: 11

ajax success function not working kindly help me

just trying to pass some values from ajax to php file, but i am getting error function working ... kindly suggest me. my codes follows

<script>
    function test(){
    //alert("hello");
    var myData ={
         name : $("#name").val(),
         email : $("#email").val(),
    };

    $.ajax({
    url: "test1.php",
    type: "POST",
    dataType:'json',
    data: {a: 155},
    success: function(data){
      console.log(data);
     },
    error : function(et){
      console.log("failed");
      alert(et);
 });
return false;}
</script>

in console i can see vales are passing, i cant find the real solution for this help

Upvotes: 0

Views: 64

Answers (1)

pr1nc3
pr1nc3

Reputation: 8338

$( document ).ready( function test(){
  //alert("hello");
  var myData ={
    name : $("#name").val(),
    email : $("#email").val(),
  };

  $.ajax({
    url: "test1.php",
    type: "POST",
    dataType:'json',
    data: {a: 155}})

    .success (function(data){
      console.log(data);
    })

    .error ( function(et){
      console.log("failed");
      alert(et);
    })
});

You had some wrong syntax + you need to tell your jquery when to execute. I set it on $( document ).ready you can modify it for onClick or whatever you want. Ajax call is working tested it in my environment.

enter image description here

Upvotes: 1

Related Questions