2012-07-29 66 views
1

我想实现jquery滑块的价格范围,我尝试调用页面web方法使用jQuery ajax但它不工作的情况下的网页方法但万一我只是将ajax调用的URL属性更改为webservice,那么它的调用就完美了。我在几个小时之内尝试了这个,并没有找到任何背后的逻辑。这里是我的代码页面web方法不工作在web服务方法调用完美的AJAX调用

<script type="text/javascript"> 
     var startPosition; 
     $(document).ready(function() {   
      var hdnMinPrice = 142; 
      var hdnMaxPrice = 969; 
      $("#slider").slider(
       { 
        min: hdnMinPrice, 
        max: hdnMaxPrice, 
        range: true, 
        values: [hdnMinPrice, hdnMaxPrice], 
        step: 50, 
        slide: function (event, ui) { 
         $('#lbl').text(ui.values[0] + ' - ' + ui.values[1]); 

        }, 
        start: function (event, ui) { 
         startPosition = ui.value; 
         //alert('Slider started at: ' + ui.value); 
        }, 
        stop: function (event, ui) {      
         $.ajax({ 
          type: "POST", 
          //url: SearchResult.aspx/FilterByPrice",              
          url: "WebService.asmx/InsetSubscriber", 
          data: "{email: '[email protected]'}", 
          contentType: "application/json; charset=utf-8", 
          dataType: "json", 
          success: function (msg) { 
           alert('Thanks'); 
           // Do something interesting here. 
          } 
         });      
         return false; 
        } 
    }); 
     }); 
    </script> 

注释掉网址选项页面web方法和下面是网页方式的定义

[WebMethod] 

    public void FilterByPrice(string email) 
    { 
     Response.Write("min" + email); 
     //Response.Write("max" + max); 
    } 

这里这是工作的Web服务方法如下:

[WebMethod] 
    public void InsetSubscriber(string email) 
    { 
     DALSubscriber objSubscriber = new DALSubscriber(); 
     objSubscriber.InsertSubscriber(email); 

    } 

我再次在这段代码段后重复我的问题。 页Web方法是行不通的,其中使用Web服务方法相同的方法在jQuery的Ajax调用运行

+0

所以在使用url调用它时在Ajax中不起作用:SearchResult.aspx/FilterByPrice是否正确? – HatSoft 2012-07-29 18:26:04

回答

2

这是因为PageMethods 必须在页面上的静态

试试这个:

[WebMethod] 
public static void FilterByPrice(string email) 
{ 
    // Use HttpContext.Current.Response instead 
    // Response.Write("min" + email); 
    //Response.Write("max" + max); 
} 
1

我建议你在httpmodule部分检查你的web.config。它必须具有的ScriptManager的ScriptModule因为网页的方法与它的工作原理

<system.web> 
    <httpModules> 
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    </httpModules> 
</system.web> 
0

添加的EnablePageMethods = “true” 和EnableScriptGlobalization = “真”

希望它会工作

+0

这应该是一个评论而不是答案。 – ryadavilli 2013-02-20 05:28:41