Page load is triggered instead of web method

OK so my sites have been working fine so far, I'm not really sure what I changed. I have a jQuery AJAX call that sends a coupon code to the server and gets a number (which is a discount).

The web method no longer runs, instead the page_page of the page on which the web method is running is run. What for? What can I check? What can I do?

Here is my handler when the button is clicked

$('div#code_apply_btn').click(function() {
    $(this).html('PLEASE WAIT');
    getpromocode();
});

      

Here is the AJAX call

function getpromocode(){
    var pcode = $('input#input_circuitcode').val();
    var hid = parseInt($('input#ss_id_h').val());
    $.ajax({
        type: "POST",
        url: "register.aspx/get_promocode",
        data: '{"promo":"' + pcode + '", "uid":' + hid + '}',
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (msg) {
            if (msg.d != -1) {
                applydiscount(msg.d);
                $('div#reg_circuit').show();
                $('div#circuit_promo').hide();
                $('div#reg_circuit').click();
            }
            else {
                $('input#input_circuitcode').val('');
                $('div#code_apply_btn').html('APPLY CODE');
            }
        },
        error: function (msg) {
            alert(msg);
        }
    });
}

      

Here's the web method

[WebMethod]
public static int get_promocode(string promo, int uid)
{
    return DAC.GetPromoCode(promo);
}

      

The web method never gets called, but the Page_load event fires and goes through everything and then gets 500 errors because it shouldn't be called and doesn't have all the data it needs.

EDIT:

All my other pages that use web methods are working fine. It's just this page.

Another strange behavior: in chrome, as soon as I start typing "register.aspx", Page_load is called. Again, all my other pages are fine, and it doesn't.

+3


source to share


2 answers


I found the answer to my question:

Since I have VS2008, I can use .Net 3.5. My server, however, has .Net 4.0 or 2.0 for some reason I cannot select 3.5 as I would like. So every time I move my project I need to change the web.config file because the default 3.5 configuration is filled with a whole bunch of things 4.0 doesn't like.

So, I remembered that I freed the web.config to a barebone version that was still working in 3.5, which is the problem. I narrowed it down to these lines which I excluded from the version running locally on 3.5



<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, 
        System.Web.Extensions, Version=3.5.0.0, Culture=neutral, 
        PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

      

I think the script module is what passes your jQuery requests to web methods, not the default page handler. There you go. But no obvious bugs or whatever, it just didn't work.

+5


source


You must have EnablePageMethods = "true" in the ScriptManager on this page.



+1


source







All Articles