且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用javascript将参数传递给WCF服务

更新时间:2023-09-03 10:58:52

#cbxReportWeek)。append( < option> + Items.ToFillReportWeekDropDownResult [i] .ReportWeekName + < /选项>中跨度>);
}

document .getElementById(' cbxReportWeek')。selectedIndex = 1 ;
}
else {
document .getElementById(' cbxReportWeek')。innerHTML = ' < option>选择Week< / option>';
}
}
xmlhttp.open( POST http:// localhost:12045 / Service.svc / ReportWeekDropDown真跨度>);
xmlHttp.setRequestHeader( Content-type application / json);
xmlhttp.send( FiscalMonth = {' + FMonth + '});
// xmlhttp.send();
alert(xmlhttp.responseXML) ;
alert(xmlhttp.responseText);
}





有没有告诉我我在哪里做错了。非常感谢任何帮助。



谢谢,

D Haraveer。


Hello Dinesh,



你可以使用jquery如下:

  //  创建Person对象,区分大小写 
var personObj = {name: Imdad,phonenumber: 91};

// 发布成功后的回调函数
var
onAddUserSuccess = function (returnData){
/ / 如果需要,使用returnData执行某些操作
};
// 发布到您的网络服务或网页


.ajax({
type: POST
url: Users.aspx / AddPerson
data:personObj,
contentType: application / json; charset = utf-8
dataType: json
成功:onAddUserSuccess
});


Hi All,

I'm developing an HTML application which I'm using only JavaScript. Here i'm able to get data when there is no need of passing parameters but while passing parameters data is not binding and also no error is throwing.

function cbReportWeek(FMonth) {
            var xmlhttp;

            //var reporturl = "http://localhost:12045/Service.svc/ReportWeekDropDown?FiscalMonth=" + FMonth;

            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            //alert(FMonth);
            xmlhttp.onreadystatechange = function () {
                debugger
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    var Items = JSON.parse(xmlhttp.responseText);
                    var data = Items;
                    var options;
                    var length = Items.ToFillReportWeekDropDownResult.length;
                    for (var i = 0; i < length; i++) {
                        $("#cbxReportWeek").append("<option>" + Items.ToFillReportWeekDropDownResult[i].ReportWeekName + "</option>");
                    }

                    document.getElementById('cbxReportWeek').selectedIndex = 1;
                }
                else {
                    document.getElementById('cbxReportWeek').innerHTML = '<option>Select Week</option>';
                }      
            }
            xmlhttp.open("POST", "http://localhost:12045/Service.svc/ReportWeekDropDown", true);
            xmlHttp.setRequestHeader("Content-type", "application/json");
            xmlhttp.send("FiscalMonth={'" + FMonth+"'}");
            //xmlhttp.send();
            alert(xmlhttp.responseXML);
            alert(xmlhttp.responseText);
        }



does any tell me where i'm doing wrong.Any help is much appreciated.

Thanks,
D Haraveer.

("#cbxReportWeek").append("<option>" + Items.ToFillReportWeekDropDownResult[i].ReportWeekName + "</option>"); } document.getElementById('cbxReportWeek').selectedIndex = 1; } else { document.getElementById('cbxReportWeek').innerHTML = '<option>Select Week</option>'; } } xmlhttp.open("POST", "http://localhost:12045/Service.svc/ReportWeekDropDown", true); xmlHttp.setRequestHeader("Content-type", "application/json"); xmlhttp.send("FiscalMonth={'" + FMonth+"'}"); //xmlhttp.send(); alert(xmlhttp.responseXML); alert(xmlhttp.responseText); }



does any tell me where i'm doing wrong.Any help is much appreciated.

Thanks,
D Haraveer.


Hello Dinesh,

You can use jquery as follow:
// create the Person object, case sensitive
var personObj = {name: "Imdad", phonenumber: "91"};

// the callback function when post is successful
var onAddUserSuccess= function(returnData) { 
  // do something with the returnData if needed 
};
// the post to your webservice or page


.ajax({ type: "POST", url: "Users.aspx/AddPerson", data: personObj, contentType: "application/json; charset=utf-8", dataType: "json", success: onAddUserSuccess });