0

For some reason when i tested parsing a json string to a dropdownlist it worked doing this

  var json = [{ "Id": "12345", "WorkUnitId": "SR0001954", "Description": "Test Service Request From Serena", "WorkUnitCategory": "ServiceRequest" }, { "Id": "12355", "WorkUnitId": "WOR001854", "Description": "Test Work Order From Serena", "WorkUnitCategory": "ServiceRequest" }, { "Id": "12365", "WorkUnitId": "DBR001274", "Description": "Test Database Related Service Request From Serena", "WorkUnitCategory": "ServiceRequest"}];

            $(json).each(function() { comboboxWorkUnit.append($('<option>').val(this.Id).text(this.WorkUnitId)); });

However when i tryed taking the json from my webservice and placing it into the dropdownlist i get an error saying the dropdownlist doesnt support this metod.

$.ajax({   
type: "POST",   
url: "Services/WorkUnitService.asmx/WorkUnit",   
data: "{'Number' : '" + Number.text()  + "','Id': '" + combobox.val() + "','workerType': '" + EmployeeType + "'}",   
contentType: "application/json; charset=utf-8",   
dataType: "json",   
success: function(json) {
$(json).each(function() { comboboxWorkUnit.append($('<option>').val(this.Id).text(this.WorkUnitId)); });

} }); 

I also tried which called the webservice method but through an error

  $.postJSON("Services/WorkUnitService.asmx/WorkUnitsForParAndPhase", "{'parNumber' : '" + parNumber + "','phaseId': '" + combobox.val() + "','workerType': '" + EmployeeType + "'}", function(data) {
        alert(data.toString()); 
        }); 

And i tryed this which never called the webservice

 $.getJSON('Services/WorkUnitService.asmx/WorkUnitsForParAndPhase' + parNumber + '/' + combobox.val() + '/' + EmployeeType,
    function(myData) {
        alert(myData.toString());
    });
HELP_ME
  • 2,619
  • 3
  • 24
  • 31

3 Answers3

0

Are you sure that your service returns a JSON object?

Adrian Toman
  • 11,316
  • 5
  • 48
  • 62
Yorgo
  • 2,668
  • 1
  • 16
  • 24
0

You might try using Fiddler2 and test the request you are sending to your web service.

Below is a working example of something similar to what you are doing, except using a GET.

$.getJSON('Service.asmx?data=123', function (data) {
    var html = '';
    var len = data[0].length;
    for (var index = 0; index < len; index++) {
        html += '<option value="' + data[0][index] + '">' + data[1][index] + '</option>';
    }
    $('#yourDivId').append(html);
});
Josh Jones
  • 174
  • 6
  • whats the difference in the two methods – HELP_ME Feb 01 '12 at 15:19
  • The method for calling data from the server isn't really important in your case, you can certainly keep the ajax "POST" that you are currently using. I just wanted to offer a suggestion for debugging the request, as well as another idea for populating the drop down list. Here is another post about creating that request in [Fiddler](http://stackoverflow.com/a/2589203/1182904). – Josh Jones Feb 02 '12 at 15:34
0

I didnt realize when using jquery in asp.net to call a webservice we were required to use .d

$.ajax({  
   type: "POST",
     url: "Services/WorkUnitService.asmx/WorkUnit",
     data: "{'Number' : '" + Number.text()  + "','Id': '" + combobox.val() + "','workerType': '" + EmployeeType + "'}",
     contentType: "application/json; charset=utf-8",  
   dataType: "json",
     success: function(json) {  
$(json).each(function() { 
alert(json.d);
 });    
HELP_ME
  • 2,619
  • 3
  • 24
  • 31