Javascript jquery post方法不工作

Javascript jquery post方法不工作,javascript,jquery,Javascript,Jquery,我使用jquery post方法提交了一个简单的表单,但是当我调用post方法时,我得到了这个wierd错误消息 VM1233 jquery.min.js:2 Uncaught TypeError: (h.dataType || "*").toLowerCase is not a function at Function.ajax (VM1233 jquery.min.js:2) at Function.w.(:8000/Marketing/anonymous function)

我使用jquery post方法提交了一个简单的表单,但是当我调用post方法时,我得到了这个wierd错误消息

VM1233 jquery.min.js:2 Uncaught TypeError: (h.dataType || "*").toLowerCase is not a function
    at Function.ajax (VM1233 jquery.min.js:2)
    at Function.w.(:8000/Marketing/anonymous function) [as post] (https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:78094)
    at submitLeadDetails (VM1235 main.js:10)
    at HTMLFormElement.onsubmit (index.html?name=haskdaskd&Contact=harish+kumar&phone=9030590437&date=12%2F04%2F2018&Time=09%3A00:33)
这是我写的代码:

var submitLeadDetails=函数(){
log('Post function executed');
var LeadDetailsObject={};
LeadDetailsObject.schoolName=document.getElementById('name').value;
LeadDetailsObject.contactPerson=document.getElementById('contact')。值;
LeadDetailsObject.contactPersonPhoneNumber=document.getElementById('phone')。值;
LeadDetailsObject.date=document.getElementById('date')。值;
LeadDetailsObject.time=document.getElementById('time').value;
控制台日志(LeadDetailsObject);
$.post($)http://localhost:8000/webapi/leads,LeadDetailsObject,函数(数据){
console.log('Success');
控制台日志(数据);
$('#leadDetailsForm')[0]。重置();
},函数(错误){
console.log('Error');
console.log(错误);
})
}

学校名称:
联系人:
电话号码:
日期:
时间:
提交

错误表明您将错误的参数传递给
.post()
方法。第四个参数应该是
数据类型
,而不是回调

见文件:

在您的情况下,您可以使用
.done()
.fail()
来处理请求的状态:

var submitLeadDetails = function(){
    console.log('Post function executed');
    var LeadDetailsObject = {};
    LeadDetailsObject.schoolName = document.getElementById('name').value;
    LeadDetailsObject.contactPerson = document.getElementById('contact').value;
    LeadDetailsObject.contactPersonPhoneNumber =document.getElementById('phone').value;
    LeadDetailsObject.date = document.getElementById('date').value;
    LeadDetailsObject.time = document.getElementById('time').value;
    console.log(LeadDetailsObject);
    $.post('http://localhost:8000/webapi/leads', JSON.stringify(LeadDetailsObject))
      .done(function(data){
        console.log('Success');
        console.log(data);
        $('#leadDetailsForm')[0].reset();
      })
      .fail(function(xhr, status, error) {
        console.log('Error');
        console.log(error);
      });
}

jQuery尝试将值小写,可能是因为进行了一些检查。但当它试图将一个数字小写时,它崩溃了。您的输入中有
type=“number”
。可能是这导致了错误。$.post的第四个参数是数据类型,而不是函数:我在代码中找不到
h.datatype
。为什么您认为
$.post
签名是
$。post(url、数据、成功、错误)
?当它是
$.post(url、数据、成功、数据类型)
?@Salman
h
位于Function.ajax的jquery.min(VM1233 jquery.min.js:2)“好的,那么我应该把最后一个参数替换为'json'@freedomn mI按照你说的更改了我的代码,现在它说的是不支持的媒体。”type@Harish此错误可能有严重的原因。在发送之前尝试
leaddailsobject=JSON.stringify(leaddailsobject)
您的数据这是因为我的数据是以表单数据的形式发送的,所以不会以我创建的对象格式发送。我应该如何阻止formdata并以我创建的格式发送数据@Orlandster@Harish我已经用
stringify
方法更新了代码片段。它是这样工作的吗?