// JScript 文件$(function () {     $("#txtSeach").keyup(function(){
        $.post("action/Seach.ashx",{plantName:$("#txtSeach").val()},function(result){
            if($.trim(result)!=""){
                $("#divListCountry").html(result);
                $("#divListCountry ul li").click(function(){
                      var data = {pages:$(this).attr("serial")};
                    
                      $.post("action/SeachId.ashx",data,function(result){
                        $("#txtSeach").val(result); 
                      
                        $("#divListCountry").css("display","none");
                    });
                });
                
                $("#divListCountry").css("display","block");
            }
        });
      
  });
  
  $("#txtSeach").blur(function(){
      setTimeout(function(){$("#divListCountry").css("display","none");},200);
  });
  
  $("#txtSeach1").blur(function(){
      setTimeout(function(){$("#divListCountry").css("display","none");},200);
  });
  
});//ashxusing System;
using System.Web;public class SeachId : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
      //  context.Response.Write("Hello World");        string aaa = context.Request.Form["pages"];//        string aer = aaa.Replace("<strong>", " ");
        string ae = aer.Replace("</strong>", " ");
       //得到:号前面值
        string str = ae.Substring(0, ae.IndexOf(":"));
      //得到:后面值
        string be = ae.Substring(ae.LastIndexOf(":") + 1);
        context.Response.Write(be);
       
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }}
这里 本地运行可以得到值 string aaa = context.Request.Form["pages"];但放到服务器上怎么都得不到从js 传过来的值,高手解决一下啊。JavaScriptashx

解决方案 »

  1.   

    没碰到过,楼主 你的Seach.ashx 可以得到值吗? 如果可以得到应该是你哪里写错了,如果得不到,那说明可能跟环境有问题,
    还有监视下 post 的数据,看看数据是否正确
      

  2.   

    用火狐的插件firebug查看下你是否提交了数据,是否接收到返回值,是否出错,出错了报的什么错,在控制台那看啊!不会的可以在详细问我
      

  3.   

     $("#divListCountry ul li").click(function(){
     $.post("action/SeachId.ashx",{pages:$(this).attr("id").val()},function(result){
    <li id="<strong> Name:</strong>Small Square with Handle (with PDQ )"> </li>id值有啊,就是服务器上面 string aaa = context.Request.Form["pages"]; 他得不到值。
      

  4.   

    在ashx里面打一个断点,先看能不能进入ashx方法在说。
      

  5.   

    <strong> Number:</strong>COLOR & ACTIVITY
    jquery 怎么去除 <strong> Number:</strong> 这段代码。
      

  6.   

    给它去个id ,
    jquery.remove() - 删除被选元素(及其子元素)
    jquery.empty() - 从被选元素中删除子元素//这个只能算清空里面的任何代码
      

  7.   


    要不这样试下, $.post("action/SeachId.ashx",{"pages":$(this).attr("id").val()},function(result){});
    或者只有一个值得话可以用url传值
     $.post("action/SeachId.ashx?pages="+$(this).attr("id").val(),function(result){});
    不过取值就要用string pages= context.Request.QueryString["pages"];
      

  8.   

    传post的时候不是传的name吗?  
      

  9.   

    $(function () {     $("#txtSeach").keyup(function(){
            $.post("action/ProductSeach.ashx",{plantName:$("#txtSeach").val()},function(result){
                if($.trim(result)!=""){
                    $("#divListCountry").html(result);
                    $("#divListCountry ul li").click(function(){
                    
                        var data = {pages:$(this).attr("id")};
                        var serial={serial:$(this).attr("serial")};                    
                        var id= $(this).attr("id");
                        var serial1=$(this).attr("serial");
                        $("#txtSeach").val(id); 
                        $("#txtSeach1").val(serial1);
                        
                        $.post("action/Home.ashx?txtSeach1="+serial1+"",function(result){  
                        
                        
                        //alert(result);
                             $("#main").html(result);
                             
                        
                        });
                        
                        $("#divListCountry").css("display","none");
                       
                    });
                    
                    $("#divListCountry").css("display","block");
                }
            });
          
      });高手指教一下,这条语句有问题吗?他在服务器上总是执行部了,但在本地是可以运行。高手指教
      

  10.   


    哎,蛋疼啊
    你想要表达什么呢,要提交什么数据过去?
    $.post("action/Home.ashx,{"txtSeach1":escape($("#txtSeach1").val())},function(result){  
        alert(result);
    });
      

  11.   


    服务器上面执行到这里就不执行了
      $.post("action/ProductSeach.ashx",{plantName:$("#txtSeach").val()},function(result){
      

  12.   

     $.post("action/ProductSeach.ashx",{plantName:$("#txtSeach").val()},function(result){ plantName???
    var plantName="xxx"?
      

  13.   

    搞错了,是string txtSeach1 = context.Request["txtSeach1"];接收不到值,
    string txtSeach1 = context.Request.QueryString["txtSeach1"];这样是可以接收到 但得不到值,不知道为什么了。
      

  14.   

    是不是有缓存? 
    $(function () {     $("#txtSeach").keyup(function(){
    //这里加个随机参数试试,保证每次请求的是不通页面,就不会去拿缓存
            $.post("action/ProductSeach.ashx?id= math.random()", {plantName:$("#txtSeach").val()},function(result){
                if($.trim(result)!=""){
                    $("#divListCountry").html(result);
                    $("#divListCountry ul li").click(function(){
                    
                        var data = {pages:$(this).attr("id")};
                        var serial={serial:$(this).attr("serial")};                    
                        var id= $(this).attr("id");
                        var serial1=$(this).attr("serial");
                        $("#txtSeach").val(id); 
                        $("#txtSeach1").val(serial1);
                        
                        $.post("action/Home.ashx?txtSeach1="+serial1+"",function(result){  
                        
                        
                        //alert(result);
                             $("#main").html(result);
                             
                        
                        });
                        
                        $("#divListCountry").css("display","none");
                       
                    });
                    
                    $("#divListCountry").css("display","block");
                }
            });
          
      });
      

  15.   

    你检查ashx文件路径是否正确,路径是否从根节点开始
    /action/ProductSeach.ashx?id= math.random()
      

  16.   

    /// <summary>
        /// 清除html标记
        /// </summary>
        /// <param name="strHtml">字符串</param>
        /// <param name="clearSpace">是否清除空格</param>
        /// <returns></returns>
        public string clearHtml(string strHtml, bool clearSpace)
        {
            if (strHtml != "")
            {
                Regex r = null;
                Match m = null;
                r = new Regex(@"<\/?[^>]*>", RegexOptions.IgnoreCase);
                for (m = r.Match(strHtml); m.Success; m = m.NextMatch())
                {
                    strHtml = strHtml.Replace(m.Groups[0].ToString().Trim(), "");
                }//exit for
            }//end if
            if (clearSpace)
            {
                strHtml = Regex.Replace(strHtml, "\\s", "");
                strHtml = strHtml.Replace("&nbsp;", "");
            }
            return strHtml;
        }
      

  17.   

     $.post("action/Seach.ashx",{plantName:$("#txtSeach").val()},function(result){下面的一般处理程序是public class SeachId : IHttpHandler 是不是你路径写错了