附加表单值到jQuery Ajax POST
Append form values to jQuery Ajax POST
我试图通过AJAX发布一个从值到远程API。
我需要从HTML表单元素的author
, string
, false
, true
。
现在我已经硬核值但是
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 = $("#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);
});
}
您可以使用$( "form" ).serialize();
这样的东西来发布您的表单值:
$.post( "http://localhost:8984/solr/techproducts/schema", $( "#testform" ).serialize() );
相关文章:
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 将curl查询转换为jQuery.ajax()
- jQuery AJAX write to XML
- jQuery Ajax GET请求工作不正常
- jquery ajax https调用给出ERR_INSECURE_RESPONSE
- VB NET JQUERY AJAX上出现错误500
- 如何使用jquery ajax和jsonp在您自己的域上读取json数据
- Jquery/Ajax.serialize()未完全工作
- 页面加载之前的jQuery Ajax加载程序
- jquery/ajax无限滚动事件
- 使用Jquery$.ajax将json数据传递给servlet(doPost)
- 如何将给定的curl命令复制为jquery ajax请求
- 使用 JQUERY AJAX (Spring MVC) 从控制器中删除
- Twitter API在jQuery AJAX中设置授权头
- AngularJS JQuery Ajax表单提交等效
- jQuery Ajax.ajaxSuccess()事件未激发
- 为什么Jquery$.ajax在函数调用中触发所有statusCode,即使调用成功
- jQuery AJAX总是出错
- jQuery Ajax数组序列化错误
- jQuery AJAX获取Vimeo缩略图