简体   繁体   中英

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]

< asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click"
                OnClientClick="return saveChanges()" />   **Script:**  var isPostBack=false; function saveChanges() { if(!isPostBack){
         PageMethods.savePageChanges(tableData, updateContent_OnSucceeded,      updateContent_onFailure);
  return false;
  }else{ 
     return true;}
   }




    function updateContent_OnSucceeded(retval) {
       isPostBack=true;
      $('# <%=btnSave.ClientID%>).click();
    }

    function updateContent_onFailure(val) {
        alert("Error: " + val.get_message());

    }**CS:**[System.Web.Services.WebMethod]
public static bool savePageChanges(List<List<string>> rowDataArraySeries)
{}

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

picker.add(newOption, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM