0

I make a total of four Ajax calls in my .NET application. Three of them work without a hitch except the last one.

Note: I HAVE to use .aspx for these calls and not mypage.aspx/mymethod because of our architectural constraints.

Ajax call that works:

$.ajax({
    type: "POST",
    url: "myaddress/GenerateOpinionHTML.aspx",
    data: JSON.stringify({ id: featureId, pageNumber: pageNumberIndex }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        SOME PROCESSING (IT WORKS)
    },
    error: function (xhr, status, error) {
        var err = xhr.responseText;
        console.log(err);
    }
});

and

[WebMethod]
public static string GenerateOpinionHTML(int id, int pageNumber)
{
    // ...
}

Ajax call that does not work:

console.log("SUBMITOPINIONCLICK");
var param = " ";
$.ajax({
    type: "POST",
    url: "myaddress/SaveOpinion.aspx",
    data: JSON.stringify({ parameter: param}),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        console.log("SAVE OPINION SUCCESSFUL");
        console.log(msg.d);
        CloseLB('GiveOpinionLB');
    },
    error: function (xhr, status, error) {
        var err = xhr.responseText;
        console.log("ERROR " + "STATUS: " + status);
    }
});

and

[WebMethod]
public static string SaveOpinion(string parameter)
{
    // ...
}

The web method SaveOpinion is never called according to the logs. Do you have any ideas or suggestions? I tried adding parameters, without parameters, checking my web.config file (though I shouldn't have since the other calls work)...

The error I get on the browser console is a "parseerror". I'm certain I wouldn't be getting an error if the method was called.

Joze
  • 3,211
  • 3
  • 34
  • 51

3 Answers3

0

I think your URL should be like

url: "Your FolderName/PageName/Function Name",

Like

url: "myaddress/SaveOpinion.aspx/SaveOpinion"

but in your code this is different so that please check.

CinCout
  • 8,291
  • 9
  • 47
  • 55
  • 1
    Please read the whole question. I specifically said that our architecture does not work like that. We HAVE to use .aspx since it is a redirection call. The other calls work except this one. – Joze May 26 '15 at 11:31
0

Have you checked if method SaveOption return something to the client? If you specify dataType as json, you should return (at least): {}

Community
  • 1
  • 1
MacGyver
  • 2,780
  • 1
  • 14
  • 14
0

Ok so we "solved" it. We just found a very dirty band-aid workaround that works.

We made a custom handler (.ashx) that we defined in our architecture as a SaveOpinion.aspx page.

We then called this custom handler page with jQuery and voilà it works, we had to obviously pass all necessary parameters manually, ie. fetching all values from textBoxes etc with jQuery and not from the context as we did before.

Since this is run in some sort of thread (I don't really know the details) we had to configure it so that it simulates the same user authentification.

Anyway I hope this provides some measure of guidance for those with this kind of obscure problems.

Joze
  • 3,211
  • 3
  • 34
  • 51