【问题标题】:How to send Form Data and other Data using AJAX如何使用 AJAX 发送表单数据和其他数据
【发布时间】:2018-08-27 22:56:29
【问题描述】:

我正在尝试使用 AJAX 发送 HTML 表单数据,但我也在尝试使用相同的 AJAX POST 调用发送其他数据。

这可能吗?

    $('#HTMLConForm').on('submit', function (e) 
{

    e.preventDefault();        
    $.ajax({
        url: "***NewUserURL.com***",
        type: "POST",
        data:{ 
              'otherinfo': otherinfo,
              'form_data': new FormData(this),
             },
        processData: false,
        contentType: false,
        success: function (data)
        {
            alert('You Have Registered')
            /*window.location = "index.html";  */
        },
        error: function (xhr, desc, err)
        {


        }
    });        
});

任何帮助都将不胜感激!

【问题讨论】:

    标签: javascript html ajax xml


    【解决方案1】:

    将 FormData 对象本身传递给data,不要将其包装在简单对象中。

    使用 FormData 对象的 append method 添加其他数据。

    e.preventDefault();     
    const formdata = new FormData(this);
    formdata.append("otherinfo", otherinfo);  
    $.ajax({
        url: "***NewUserURL.com***",
        type: "POST",
        data: formdata,
    

    【讨论】:

      猜你喜欢
      • 2016-11-24
      • 2017-08-17
      • 1970-01-01
      • 2014-03-06
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      相关资源
      最近更新 更多