// 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
$.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
还有监视下 post 的数据,看看数据是否正确
$.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"]; 他得不到值。
jquery 怎么去除 <strong> Number:</strong> 这段代码。
jquery.remove() - 删除被选元素(及其子元素)
jquery.empty() - 从被选元素中删除子元素//这个只能算清空里面的任何代码
要不这样试下, $.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"];
$.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");
}
});
});高手指教一下,这条语句有问题吗?他在服务器上总是执行部了,但在本地是可以运行。高手指教
哎,蛋疼啊
你想要表达什么呢,要提交什么数据过去?
$.post("action/Home.ashx,{"txtSeach1":escape($("#txtSeach1").val())},function(result){
alert(result);
});
服务器上面执行到这里就不执行了
$.post("action/ProductSeach.ashx",{plantName:$("#txtSeach").val()},function(result){
var plantName="xxx"?
string txtSeach1 = context.Request.QueryString["txtSeach1"];这样是可以接收到 但得不到值,不知道为什么了。
$(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");
}
});
});
/action/ProductSeach.ashx?id= math.random()
/// 清除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(" ", "");
}
return strHtml;
}