当我从XMLHttpRequest中得到一个响应时,我如何处理*响应*;张贴“;活动

How do I handle the *response* when I get one back from an XMLHttpRequest "Post" operation?

本文关键字:响应 何处理 活动 处理 张贴 一个 XMLHttpRequest      更新时间:2023-09-26

我在这方面遇到了很多困难——我似乎在兜圈子
我要做的是将数据从客户端上的javascript POST到web服务。

在以下示例中,valFnamevalLnamevalPhonevalZip都具有有效的字符串值:

function checkOffers(){
   // data collection from loaded form...

        var postData = "'FirstName':'" + valFname ;
        postData +="','LastName':'" + valLname ;
        postData +="','PhoneNumber':'" + valPhone ;
        postData += "','Zipcode':'" + valZip+"'";
        initialize(postData);
}

function initialize(postData) {
    //var postMsg = createSoapHeader(msg);
    var url = "https://server.company.com:9999/analytics/webservices/webservice.asmx/SamplePriorityOfferList";
    request.open("POST", url, false)
    request.onreadystatechange = function(){
        if(this.readyState===4){
            //request is complete.  handle it
            processData;
        }
    };
    request.send(postData);
}
function processData(){
     response = request.responseXML.xml;
     alert("Returned Data:" + response);
}

我在PageLoad事件上调用checkOffers函数-我希望web服务在不必单击按钮、链接等的情况下启动

我正在从请求中返回null,但应该正在获取数据。如有任何意见、提示或建议,我们将不胜感激。

此行:

        if(this.readyState===4){ 

应该是:

        if(this.readyState==4){

这至少会让你看到警报。