【问题标题】:Sending values of a form with ajax via post使用 ajax 通过 post 发送表单的值
【发布时间】:2012-10-02 16:03:44
【问题描述】:

我试图通过 ajax 中的 POST 以表单形式发送值,我如何在发送时捕获它们,这是我现在在 GET 中所拥有的

    function test(ans_field_uuid){
        var result = "";
        var url="ajax_pages/remove_answer_field_ajax.php"
        url += '?uuid=' + ans_field_uuid;
        $.get(
        url,
        function (data) {
            result = data;
        }
    )
        .success(function () {
            if (result != "") {
                addTableRow('tb_add_field', result);
                $('#ajaaxDiv').html(result);
            }
        })
        .complete(function () {
            $('#img_create_subcat').hide();
            $('#dialog').dialog('close');
        })
        .error(function () {
            alert('An error has occurred.');
        });
        return false;
    }

【问题讨论】:

标签: javascript jquery html ajax


【解决方案1】:

因为你已经使用了 jQuery

$.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

数据:名称和位置是您的 POST 变量。 您可以在 some.php 中获取此示例中的 POST 变量

$_POST["name"]

等于“约翰”

如果您想收到类似“Hello”的信息。 在你的 some.php 中

echo "Hello";

它会作为变量 msg 发送到你的 ajax 函数作为你的 done 函数中的响应

【讨论】:

【解决方案2】:

jQuery post 的文档

// ...

var url = "ajax_pages/remove_answer_field_ajax.php";

$.post( url, "uuid=" + ans_field_uuid, function (data) {
    result = data;
}
// ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多