简体   繁体   English

将get参数放入post请求

[英]Put get parameters into post request

I am submitting a form via an ajax post request but there is a possibility that there is also one get parameter and if the get parameter is set it must be included in the post request.我正在通过 ajax post 请求提交表单,但有可能还有一个 get 参数,如果设置了 get 参数,则它必须包含在 post 请求中。 I currently have this:我目前有这个:

jQuery(document).ready(function($) {
   $("#plugin_check").submit(function(e) {
    e.preventDefault(); // avoid to execute the actual submit of the form.

    var form = $(this);
    var actionUrl = form.attr('action');
    
    $.ajax({
        type: "POST",
        cache: false,
        url: actionUrl,
        data: form.serialize(), // serializes the form's elements.
        success: function(data)
        {
          $("#result").html(data); // show response from the php script.
        }
    });
  });  
});

I need to figure out how to put $_GET['datesort'] into the post data.我需要弄清楚如何将 $_GET['datesort'] 放入发布数据中。

you can try this, create variable to save datesort and add this to ajax data你可以试试这个,创建变量来保存日期排序并将其添加到ajax数据

jQuery(document).ready(function($) {
  $("#plugin_check").submit(function(e) {
    e.preventDefault(); // avoid to execute the actual submit of the form.

    var form = $(this);
    var actionUrl = form.attr('action');
    var queryString = window.location.search;
    var urlParams = new URLSearchParams(queryString);
    var datesort = urlParams.get('datesort')

    $.ajax({
      type: "POST",
      cache: false,
      url: actionUrl,
      data: form.serialize() + `&datesort=${datesort}`, // serializes the form's elements.
      success: function(data) {
        $("#result").html(data); // show response from the php script.
      }
    });
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM