好的,现在我发布这样的数据:
function post_to_url(path, params, method) {
console.log ("Inside post_to_url>>>>>>>>");
method = method || "post"; // Set method to post by default, if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
并将此方法称为:
function handleLogin()
{
var form = $("#loginForm");
var u = $("#username", form).val();
var p = $("#password", form).val();
var d = $("#dob", form).val();
if(u != '' && p!= '')
{
var finalStr = u+encodeURIComponent("|^")+p+encodeURIComponent("|^")+encodeURIComponent("|^")+"X"+encodeURIComponent("|^")+d+encodeURIComponent("|^")+"1.0"+encodeURIComponent("|^|$");
var encodedURL = encodeURI(intranetUrl+"customer/Ri_logon.asp?requestString=");
var parameters = decodeURIComponent(finalStr);
console.log("before calling post_to_url method");
post_to_url(encodedURL,parameters,'post');
}
else
{
alert("You must enter a username and password", function() {});
$("#submitButton").removeAttr("disabled");
}
}
但现在我从服务器获取输出为:“不是对象”。当参数暂停或特殊字符未完美编码时,它来自服务器。但是我已经像上面的原始问题一样对参数进行了编码。那为什么会这样呢?