Javascript 将表单值附加到jQuery Ajax POST
我正试图通过AJAX将一个从值到远程API的消息发布 我需要HTML表单元素中的Javascript 将表单值附加到jQuery Ajax POST,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我正试图通过AJAX将一个从值到远程API的消息发布 我需要HTML表单元素中的作者,字符串,假,真 现在我已经坚定地接受了我的价值观 function sendData() { var settings = { "async": true, "crossDomain": true, "timeout":8000, "url": "http://localhost:8984/solr/techproducts/
作者
,字符串
,假
,真
现在我已经坚定地接受了我的价值观
function sendData() {
var settings = {
"async": true,
"crossDomain": true,
"timeout":8000,
"url": "http://localhost:8984/solr/techproducts/schema",
"method": "POST",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache",
"Access-Control-Allow-Origin":"*"
},
"processData": false,
"data": "{\"replace-field\":{\"name\":\"author\",\"type\":\"string\",\"stored\":false,\"indexed\":true} }"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
}
像这样试试
var requestData = {
id : $('#id').val(),
commentLiveStatusStageChange:$('#'+textid).val(),
currentLiveStatusStage:$('#stage').val()
}
var settings = {
"async": true,
"crossDomain": true,
"timeout":8000,
"url": "http://localhost:8984/solr/techproducts/schema",
"method": "POST",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache",
"Access-Control-Allow-Origin":"*"
},
"processData": false,
"data": requestData
}
您可以序列化formdata,然后附加它 例:
formData=$(“#myForm”).serialize()
然后在ajax请求中使用formdata
function sendData() {
formData = $("#myForm").serialize() //myForm should be replaced with your form's id
var settings = {
"async": true,
"crossDomain": true,
"timeout":8000,
"url": "http://localhost:8984/solr/techproducts/schema",
"method": "POST",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache",
"Access-Control-Allow-Origin":"*"
},
"processData": false,
"data": formData
}
$.ajax(settings).done(function (response) {
console.log(response);
});
}
您可以使用$(“表单”).serialize()代码>类似这样的内容来发布表单值:
$.post( "http://localhost:8984/solr/techproducts/schema", $( "#testform" ).serialize() );
我想从HTML表单中获取这些字段的值。您可以将ID设置为HTML字段并访问它们。$(“#idofneedfield”).val()