Post form with Ajax and jQuery

前端 未结 3 1624
-上瘾入骨i
-上瘾入骨i 2021-01-27 10:39

Start learning Ajax (and jQuery), I encounter the issue with post form data, which I could not resolve myself.

First, here is the simple example where I collect data, po

相关标签:
3条回答
  • 2021-01-27 11:09

    Try this.

    $(document).ready(function(){ 
        $("#myButton").click(function() { 
            $.ajax({
            cache: false,
            type: 'POST',
            url: 'test.php',
            data: $("#myForm").serialize(),
            success: function(data){
            alert(data);
            }
            });
        }); 
    });
    
    0 讨论(0)
  • 2021-01-27 11:15

    You're going to need a success callback, which I'll assume will be some HTML...

    $(document).ready(function(){ 
        $("#myButton").click(function() { 
            $.ajax({
            cache: false,
            type: 'POST',
            url: 'test.php',
            data: $("#myForm").serialize(),
            success: function(response) {
                $("#someElement").html(response);
            }
            });
        }); 
    });
    
    0 讨论(0)
  • 2021-01-27 11:25

    I believe you're looking for the success in the .ajax options parameter.

    $.ajax({
      ...
      success: function(d){
        alert(d);
      }
    });
    
    0 讨论(0)
提交回复
热议问题