0

使用 post 提交表单时,如果我不希望它序列化(或作为字符串,我觉得不安全)并希望它以与不使用 jquery 时相同的方式提交怎么办?我怎么能那样做?

$.ajax({
        type: "POST",
        data: $("#sform").serialize(), //don't want to use this part. Want it go just like it would without using jquery

这些数据是“必须”使用的吗?有什么替代方案?

4

1 回答 1

1

并希望它以与我不使用 jquery 时相同的方式提交?

这正是该.serialize()方法所做的 :-) 它使用application/x-www-form-urlencoded编码格式化表单数据,这是 html 表单的默认格式。因此,如果您希望服务器以与未使用 javascript完全相同的格式.serialize()接收数据,请使用该方法。

AJAXify 表单的标准方法如下:

$(function() {
    $('#sform').submit(function() {
        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            success: function(result) {

            }
        });
        return false;
    });
};

Now whether the user has javascript disabled or not, the server will receive the form POST in exactly the same way.

于 2012-08-19T08:20:56.097 回答