Click here to Skip to main content
15,891,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

JavaScript
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.
Posted

1 solution

Hello Dinesh,

You can use jquery as follow:
JavaScript
// 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
});
 
Share this answer
 
Comments
Dinesh1207 19-Jun-13 7:11am    
i have tried before the above code but it is not going to success method going to error method
Sunasara Imdadhusen 19-Jun-13 8:15am    
What is error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900