【问题标题】:Sending data gives [object HTMLInputElement] as query response发送数据将 [object HTMLInputElement] 作为查询响应
【发布时间】:2020-09-05 19:25:05
【问题描述】:

我正在尝试将用户表单数据发送到合作伙伴端点,如下所示:

$('#registrationFrm').on('submit', function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "https://pixel.plexop.com/?country="+countryid+"&_v=6&name="+firstName+"&lastname="+lastName+"&phone="+phone
+"&email="+emailid+"&ud=&e=2&adv=1&a=4&f=221161&FormId=1807&SerialId=1210053",
data: $("#registrationFrm").serialize(),
success: function() {
alert('success');
 }
});
});

我得到了 200 个“OK”回复,但是当我在“网络”上检查它时,我收到了这个数据:

Query string: country   "[object HTMLSelectElement]
Query string: name  "[object HTMLInputElement]
Query string: lastname  "[object HTMLInputElement]"

我的表单如下所示:

<form id="registrationFrm" >
      <div class="form-group has-feedback">
        <input type="text" class="form-control" placeholder="First Name" name="firstName" id="firstName" required />
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" placeholder="Last Name" name="lastName" id="lastName" required />
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="tel" class="form-control" placeholder="Phone No" name="phone" id="phone" required />
        <span class="glyphicon glyphicon-earphone form-control-feedback"></span>

我在这里做错了什么?

【问题讨论】:

  • 你能发布一个完整的代码示例吗?查看 countryidfirstNamelastNamephoneemailid 的所有 var 声明以及表单字段的相关 HTML 会有所帮助。
  • 所以您是在 URL 和请求正文中发送数据?

标签: html ajax forms api


【解决方案1】:

可能,您定义变量如下:

const firstName = document.getElementById('firstName');
/*and so*/

但你应该这样做:

const firstName = document.getElementById('firstName').value;

UPD:

$('#registrationFrm').on('submit', function (e) {
    e.preventDefault();
    $.ajax({
        type: 'POST',
        url:
            'https://pixel.plexop.com/?country=' +
            countryid.value +
            '&_v=6&name=' +
            firstName.value +
            '&lastname=' +
            lastName.value +
            '&phone=' +
            phone.value +
            '&email=' +
            emailid.value +
            '&ud=&e=2&adv=1&a=4&f=221161&FormId=1807&SerialId=1210053',
        data: $('#registrationFrm').serialize(),
        success: function () {
            alert('success');
        }
    });
});

【讨论】:

  • 我根本没有添加任何 const 。这应该在 index.html 中实现吗?
  • 你最好这样做,但你可以这样做:再次检查我的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-27
  • 1970-01-01
  • 2021-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多