locked
AJAX webmethod declaration in VS 2015 RRS feed

  • Question

  • User280982355 posted

    I have recently upgraded to VS 2015, and I now have trouble with declaring AJAX webmethods using VB, specifically the underscore.

    I have this declaration:

    Public Class AJAX
        Inherits System.Web.UI.Page
           <System.Web.Services.WebMethod()>
        Public Shared Sub opdaterVideoStat(ByVal playlist_id As Integer)
            TV2BGlobal.opdaterVideoStatistik(playlist_id)
        End Sub
       
    End Class

    As I understand it there MUST be an underscore after the webMethod()> for this to Work, but visual studio 2015 automatically removes it every time I try to insert it.

    And I cannot get the AJAX functionality to work.

    I have another application which has been ported from VS 2012 to VS 2015, and in that app the underscore stays, and the AJAX functionality works.

    Whats up with this?

    Monday, January 25, 2016 1:38 PM

Answers

  • User753101303 posted

    So it really seems unrelated to line continuation characters (else you would have a compile time error). And so you don't even have a 404 not found http error (using F12 in your browser)? You are posting to another page than the one on which you are?

    Ah, 'Play videostat opdateret: ' & playlist_id shouldn't be correct. Client side it is + rather than & which is used in VB.NET. You still may have other error (and I don't remember to have ever seen some code that just "stops" without any error of any kind).

    I'll try to give this a closer look as it might be an interesting case for a debugging tutorial.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 26, 2016 12:34 PM

All replies

  • User753101303 posted

    Hi

    I cannot get the AJAX functionality to work.

    Please ALWAYS tell rather what actually happens rather than basically that "it doesn't work". Do you have a compilation error because the _ continuation line character is removed or does it compilte fine?

    I don't have VS2015 handy right now but I believe it could be just that it has been improved at some point and so it is removed because it is just not needed: http://thebuildingcoder.typepad.com/blog/2011/06/implicit-line-continuation-in-vb-2010.html

    So more likely it is just unrelated to your current issue.

    So as usual, it's likkely best to start by telling us what is the error message or the bad behavior you see so that we can see what cause the particular error/behavior you describe rather than having to guess among the zillion of possible issues that could cause something that should work to "not work".

    Monday, January 25, 2016 6:45 PM
  • User280982355 posted

    Yes Ive read about the implicit line continuation - but as my ported app has retained the underscores I assume that they are still significant.

    My JavaScript code calls the Ajax like so

      console.info('AJAX opdatér videostatistik: ' + playlist_id);
        $.ajax({
            type: "POST",
            url: "userControls/AJAX.aspx/opdaterVideoStat",
            data: '{playlist_id: ' + playlist_id + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) { console.log('Play videostat opdateret: ' & playlist_id); },
            failure: function (response) { console.error(response.d) }
        });

    but the tracking stops at the JavaScript Ajax call (and no JavaScript errors). The code never returns from the Ajax and the code in the Ajax.vb opdaterVideoStat is never invoked.

    I dont even get the failure response from the JavaScript.

    Tuesday, January 26, 2016 8:19 AM
  • User753101303 posted

    So it really seems unrelated to line continuation characters (else you would have a compile time error). And so you don't even have a 404 not found http error (using F12 in your browser)? You are posting to another page than the one on which you are?

    Ah, 'Play videostat opdateret: ' & playlist_id shouldn't be correct. Client side it is + rather than & which is used in VB.NET. You still may have other error (and I don't remember to have ever seen some code that just "stops" without any error of any kind).

    I'll try to give this a closer look as it might be an interesting case for a debugging tutorial.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 26, 2016 12:34 PM
  • User280982355 posted

    Ah yes you are right about the "&"

    I have corrected the "&" to the correct "+", but it changed nothing in the execution

    Also tried changing the WebMethod opdaterVideoStat (which was a sub) to a function with a return value - though it does work as a sub in my other app - just trying to eliminate possible causes - Again that changed nothing....

    And it is strange with the no-error scenario - it is as if the ajax-call is succesfully received but never returns anything...which is weird

    Looking forward to your findings 

    BTw. VS 2012 accepts compilation both with and without the "underscore" character, and I seem to recall that if you forget the underscore it doesnt work and if you remember it, it Works...

    Tuesday, January 26, 2016 1:07 PM
  • User61956409 posted

    Hi cjohs,

    As PatriceSc said, you could use F12 developer tools Network tool to check request status.

    https://msdn.microsoft.com/en-us/library/dn255004(v=vs.85).aspx

    Best Regards,

    Fei Han

    Thursday, January 28, 2016 8:40 AM