weixin_33743661 2014-09-30 07:41 采纳率: 0%
浏览 21

从ajax发送数据到php

  <script>
      var er ="hi";

      $( "#save" ).click(function() {
      var er = $('#edit').val();
      alert(er);

    });

 $.ajax({  
    type: 'POST',  
    url: 's.php', 
    data: { er:er},
    success: function(response) {
        alert(er);
                                }
            });
  </script>
  • 写回答

1条回答 默认 最新

  • weixin_33743880 2014-09-30 07:46
    关注

    You must write the ajax code in click function, otherwise ajax code will execute on page load.

    var er ="hi";
    
    $( "#save" ).click(function() {
       var er = $('#edit').val();
       alert(er);
       $.ajax({  
         type: 'POST',  
         url: 's.php', 
         data: {'er':er},
         success: function(response) {
            alert(er);
         }
       });
    });
    

    Try above code. it will work for you.

    评论

报告相同问题?