-1

嗨,我想以 post 方法将数据发送到服务器。我知道这是一个简单的问题,但我没有得到很好的文件。我有将数据发送到服务器的方法,但它使用的是 ajax。我想在没有ajax的情况下发送数据怎么做?这是我的代码。

 $.ajax({
                type: "POST",
                contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                url: clientDetailURL,
                data: finalclientDetailParam
                }).done(function( msg1 )
                {
                         var clientDetailResponse = msg1;
                         console.log("Client detail response is:"+clientDetailResponse);
                 });
4

1 回答 1

0

好的,现在我发布这样的数据:

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");
}


}

但现在我从服务器获取输出为:“不是对象”。当参数暂停或特殊字符未完美编码时,它来自服务器。但是我已经像上面的原始问题一样对参数进行了编码。那为什么会这样呢?

于 2012-07-08T09:09:53.047 回答