如何传递不在URL中的多个参数?

时间:2021-12-03 14:09:10

Currently the form data is passed via the URL, like below.

目前,表单数据通过URL传递,如下所示。

document.getElementById('newChildForm').action = "./populateImageProcessing?personId="+ temp+ "&category="+ strUser+ "&fromDate="+ frmDate+ "&toDate=" + toDate+"&advFromDayID="+advFromDayID+"&advFromMonthID="+advFromMonthID+"&advFromYearID="+advFromYearID+"&advToDayID="+advToDayID+"&advToMonthID="+advToMonthID+"&advToYearID="+advToYearID;

document.getElementById('newChildForm').submit();

I want to pass the form data separately, and not via the URL.

我想单独传递表单数据,而不是通过URL。

I tried the below with ajax/jQuery

我用ajax / jQuery尝试了下面的内容

$.ajax({
        cache: false,
        url : "./populateImageProcessing",
        type : "POST",
        data : "personId=" + temp + "&category="
                    + strUser
                    + "&fromDate="+ frmDate+ "&toDate=" + toDate+ "&advFromDayID="+advFromDayID+"&advFromMonthID="+advFromMonthID+"&advFromYearID="+advFromYearID+"&advToDayID="+advToDayID
                    +"&advToMonthID="+advToMonthID+"&advToYearID="+advToYearID,
success: function(data){
$("#newChildForm").html(data); 
}
 }); 

The jQuery working in SIT environment, but I've some trouble in UAT environment due to CSP.

jQuery在SIT环境中工作,但由于CSP,我在UAT环境中遇到了一些麻烦。

Is there any way could use plain javascript document.getElementById('newChildForm').action="./populateImageProcessing", and pass the parameters separately, and not in the URL.

有没有办法可以使用普通的javascript document.getElementById('newChildForm')。action =“./ populateImageProcessing”,并分别传递参数,而不是在URL中。

Please help. Thank you.

请帮忙。谢谢。

2 个解决方案

#1


1  

Try with this code :

试试这段代码:

var data = "personId=" + temp + "&category="+ strUser+ "&fromDate="+ frmDate+ "&toDate=" + toDate+ "&advFromDayID="+advFromDayID+"&advFromMonthID="+advFromMonthID+"&advFromYearID="+advFromYearID+"&advToDayID="+advToDayID+"&advToMonthID="+advToMonthID+"&advToYearID="+advToYearID;

var xhttp= new XMLHttpRequest();

xhttp.open("POST", "populateImageProcessing", true);

xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('newChildForm').innerHTML = this.responseText
       }
    };

xhttp.send(data); 

#2


0  

Have you tried something like this ?
Json is a good way to pass multiple parameters.

你尝试过这样的事吗? Json是传递多个参数的好方法。

var obj = { personId: temp, category: strUser, fromDate: frmDate, toDate: toDate, advFromDayID :advFromDayID, advFromMonthID: advFromMonthID, advFromYearID: advFromYearID, advToDayID: advToDayID, advToMonthID: advToMonthID, advToYearID: advToYearID };
$.ajax({
    cache: false,
    url: "./populateImageProcessing",
    type: 'POST',
    data: JSON.stringify(obj),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(data){
        $("#newChildForm").html(data); 
    }
});

But I don't know if you can handle it on the "server" side ?
Tell me. Hope it helps.

但我不知道你是否可以在“服务器”端处理它?告诉我。希望能帮助到你。

#1


1  

Try with this code :

试试这段代码:

var data = "personId=" + temp + "&category="+ strUser+ "&fromDate="+ frmDate+ "&toDate=" + toDate+ "&advFromDayID="+advFromDayID+"&advFromMonthID="+advFromMonthID+"&advFromYearID="+advFromYearID+"&advToDayID="+advToDayID+"&advToMonthID="+advToMonthID+"&advToYearID="+advToYearID;

var xhttp= new XMLHttpRequest();

xhttp.open("POST", "populateImageProcessing", true);

xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('newChildForm').innerHTML = this.responseText
       }
    };

xhttp.send(data); 

#2


0  

Have you tried something like this ?
Json is a good way to pass multiple parameters.

你尝试过这样的事吗? Json是传递多个参数的好方法。

var obj = { personId: temp, category: strUser, fromDate: frmDate, toDate: toDate, advFromDayID :advFromDayID, advFromMonthID: advFromMonthID, advFromYearID: advFromYearID, advToDayID: advToDayID, advToMonthID: advToMonthID, advToYearID: advToYearID };
$.ajax({
    cache: false,
    url: "./populateImageProcessing",
    type: 'POST',
    data: JSON.stringify(obj),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(data){
        $("#newChildForm").html(data); 
    }
});

But I don't know if you can handle it on the "server" side ?
Tell me. Hope it helps.

但我不知道你是否可以在“服务器”端处理它?告诉我。希望能帮助到你。