0

Please see the code below:

<script type="text/javascript"  src="Javascript/json2.js"></script>
     <script type="text/javascript" src="Javascript/jquery-1.11.1.min.js"></script>
<script type = "text/javascript">
function GroupUSNChange() {
        alert("got here");
        var frm = document.forms[0];
        var usn = document.getElementById("ctl00_ContentPlaceHolder1_hfUSN");
        for (i = 0; i < frm.elements.length; i++) {
            if (frm.elements[i].type == "checkbox" && frm.elements[i].name.substr(0, 38) == "ctl00$ContentPlaceHolder1$RematchGroup") {
                if (frm.elements[i].checked == true) {

                    var id = frm.elements[i].name.split("|");
                    alert(id[1]);
                    alert(id[2]);
                    alert(usn.value);

                    $.ajax({
                        type: "POST",
                        url: "frmPNList.aspx/ChangeGroupOfUSNs",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify({ strNewUSN: usn, strURNs: id(1), strDatasetName: id(2) }),
                        dataType: "json",
                        success: OnSuccess(response),
                        error: function (xhr, errorType, exception) {
                            var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText  
                            alert("there was an error changing USNs: " + errorMessage);
                        },
                        failure: function (response) {
                            alert('there was a problem changing USNs.')

                        }
                     });
                    function OnSuccess() {
                        return function (response) {
                            //alert('got here 2')
                            alert('Successfully changed USNs')
                        }
                    }



                }
            }
        }
    }
</script>

and the code behind:

<System.Web.Services.WebMethod()> _
    Public Shared Function ChangeGroupOfUSNs(ByVal strNewUSN As String, ByVal strURNs As String, ByVal strDatasetName As String) As String

        Dim intUSN As Integer = CInt(strNewUSN)

        Return "done"
    End Function

The error is on the line that starts: $.ajax({

id and USN contain the correct values. Why do I get this error?

1 Answer 1

5

You're CALLING your success handler:

success: OnSuccess(response),
                  ^^^^^^^^^^

when it should be more like:

success: function(data) { OnSuccess(data); }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.