Search code examples
javascriptasp.netjsonjquerypagemethods

Calling asp.net page method from javascript not working in Firefox


I am using PageMethod w/ javascript to call server-side code:

 function getMonths() {

   PageMethods.BindMonthlyPeriods(getMonthsSuccess, onFailure);            }
 }

 function getMonthsSuccess(result, userContext, methodName) {

    var picker = document.getElementById("monthPicker");

    for (var i = 0; i < result.length; i++) {

        var newOption = document.createElement('option');
        newOption.text = result[i];
        newOption.value = result[i];

        picker.add(newOption); 
    }
}

With this in code-behind:

    [WebMethod]
    public static string[] BindMonthlyPeriods()
    {

    }

This works fine in IE / Chrome but not in firefox. No specific error msg the data just doesnt populate in firefox.

Ive also tried using a jQuery ajax call instead but that isnt working, though I'm not sure I've done it correctly:

 function getMonths() {

    $.ajax({
        type: "POST",
        url: "page.aspx/BindMonthlyPeriods",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {

            var picker = document.getElementById("monthPicker");

            for (var i = 0; i < msg.length; i++) {

                var newOption = document.createElement('option');
                newOption.text = result[i];
                newOption.value = result[i];

                picker.add(newOption);
            }

        }
    });

EDIT

Using Firebug I did not find any error msgs in the Net tab but did find this error in the Console tab:

uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://xxxxx.xxxxxxx.com/.../page.aspx :: getMonthsSuccess :: line 251" data: no]


Solution

  • Solved this by adding null parameter to the 'add' method of the monthpicker:

    picker.add(newOption, null);