Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将表单值附加到jQuery Ajax POST_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript 将表单值附加到jQuery Ajax POST

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/

我正试图通过AJAX将一个从值到远程API的消息发布

我需要HTML表单元素中的
作者
字符串

现在我已经坚定地接受了我的价值观

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()