dqqpf32897 2017-11-17 07:55
浏览 33

ajax成功功能不合作帮助我

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

  • 写回答

1条回答 默认 最新

  • dongshuo9350 2017-11-17 08:03
    关注
    $( 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

    评论

报告相同问题?