页面加载,而不是解雇Web方法 [英] Page load is fired instead of web method

查看:109
本文介绍了页面加载,而不是解雇Web方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我的网站已经正常工作到现在为止,我真的不知道我已经改变了。我有一个jQuery AJAX调用发送的优惠券code到服务器,并检索了一些(这是优惠)。

OK, so my websites been working normally up until now, I'm not really sure what I've changed. I have a jQuery AJAX call that sends a coupon code to the server, and retrieves a number (which is the discount).

将WebMethod不再被解雇,虽然,而不是在Page_Load这将WebMethod是上被解雇页面。为什么?我可以检查?我该怎么办?

The Webmethod is no longer being fired though, instead the Page_load of the page which the webmethod is on is being fired. Why? What can I check? What can I do?

下面是我的按钮被按下时的处理程序

Here is my handler for when the button is clicked

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

下面是AJAX调用

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);
        }
    });
}

下面是将WebMethod

Here's the webmethod

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

将WebMethod不会被调用,但Page_Load事件火灾和贯穿一切都那么它得到一个500错误,因为它不应该叫,也没有它所需要的所有数据。

The webmethod is never called, but the Page_load event fires and runs through everything then it gets a 500 error because it shouldn't be called and doesn't have all the data it needs.

编辑:

这是使用网络的方法做工精细所有我的其他页面。这只是这个页面。

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

奇怪的行为的另一个位:一旦在铬,我开始键入register.aspx,在Page_Load被调用。再次我所有的网页都很好,这不会发生。

Another bit of strange behaviour: In chrome as soon as I begin to type "register.aspx", the Page_load is called. Again all my other pages are fine and this doesn't happen.

推荐答案

我已经找到了答案,我的问题:

I have found the answer to my question:

由于我有VS2008我只能用NET 3.5的。我的服务器已经但是.NET不管出于什么原因,我不能选择3.5,因为我本来希望到4.0或2.0。所以每次我将我的项目,我必须改变web.config中,因为默认配置3.5充满了一大堆东西,4.0不喜欢。

Because I have VS2008 I can only use .Net 3.5. My server however has .Net 4.0 or 2.0 for whatever reason I can't choose 3.5 as I would have liked to. So everytime I move my project I have to change the web.config because the default 3.5 config is filled with a whole bunch of stuff that 4.0 doesn't like.

于是我想起,我已经掏空了web.config中仍先后在3.5这是问题的所在准系统版本。我把范围缩小到我从版本运行在本地排除3.5这些行

So I remembered that I had emptied out the web.config to a barebone version that still worked in 3.5 which is where the problem is. I narrowed it down to these lines which I had 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>

我猜的脚本模块是通过你的jQuery请求的Web方法,而不是默认的页面处理程序。你去那里。但没有明显错误或任何东西,它只是没有工作。

I guess the script module is what passes your jQuery requests to the web methods rather than the default page handler. There you go.. But no obvious errors or anything, it just didn't work.

这篇关于页面加载,而不是解雇Web方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆