前臺(tái)JS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>??? <title>New Document </title><script type="text/javascript" src="js/jquery-1.4.1.js"></script><script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">?function aj(){?alert("fsdf");?var openId=null;//'0E0C36C83EA68C8058F9ACE3CBFDDCEE';?$.post(??????????????? "Handle.aspx",??????????????? { openId:openId},??????????????? function (data){??????????????? alert("返回"+data);?????????????? if(data){???????????????? alert("0返回"+data);?????????????????? window.location.;????????????? ?????????????? }else{??????????????? alert("1返回aa"+data);??????????????? window.location.+openId;?????????????? }??????????? });
?? }??????????? </script>
?</head><body><span id="wb_connect_btn"></span>??? <input id="Button1" onclick="aj();" type="button" value="button" />
</body></html>
?
后臺(tái)cs
?protected void Page_Load(object sender, EventArgs e)??????? {
??????????? if (HttpContext.Current.Request["openId"] != null)??????????? {
??????????????? Suridea.CloudService.Model.User user = new Suridea.CloudService.Model.User();??????????????? user.Remark = Request["openId"].ToString();??????????????? IList<User> u = userService.FindUsers(user);??????????????? bool result=false;??????????????? if (u.Count != 0)??????????????? {??????????????????? result = true;
??????????????? }??????????????? else {??????????????????? result = false;??????????????? }??????????????? HttpContext.Current.Response.ContentType = "text/plain";??????????????? HttpContext.Current.Response.CacheControl = "no-cache";??????????????? HttpContext.Current.Response.Write(result);??????????????? HttpContext.Current.Response.Flush();
???????????? ??????????? }??????? }
以上為我js代碼 很頭疼啊 處理代碼
我代碼異步回調(diào)成功了 返回data有時(shí)候明明是false卻還是跑到if里面,然后我把data改為返回字符串還是if條件那判斷感覺沒起到效果。很頭疼很急的問題 搞了一天了 都沒弄出來(lái)哪的問題,希望幫忙快點(diǎn)解決,在線等。
11 回答

守著一只汪
TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
貼主看了你的代碼,你將數(shù)據(jù)提交到了一個(gè)aspx文件來(lái)處理,為了以絕后患!?。?/p>
?
我教你一個(gè)方法。
?
新建一個(gè)"一般處理程序”。后綴是ashx文件。
?
寫入以下代碼:
?
public void ProcessRequest(HttpContext context) { if (context.Request["openId"] != null) { if (context.Request["openId"] != null) { Suridea.CloudService.Model.User user = new Suridea.CloudService.Model.User(); user.Remark = context.Request["openId"].ToString(); IList<User> u = userService.FindUsers(user); bool result = false; if (u.Count != 0) { result = true; } else { result = false; } context.Response.ContentType = "text/plain"; context.Response.CacheControl = "no-cache"; context.Response.Write(result); context.Response.Flush(); } } }

DIEA
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
data=false 謝謝大家對(duì)我的指點(diǎn),你們說(shuō)的我都試過了,還是讓它直接返回連接路徑算啦,不過if那里判斷不起作用,很納悶。不知道哪的問題。

MMMHUHU
TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
@lin_yue:?
后臺(tái)輸出返回到data里的是字符串"false"而不是bool值,任何不為空的字符串都為真,當(dāng)然進(jìn)if里面了,詳見我上面的回復(fù)。

慕無(wú)忌1623718
TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
data里面是字符串,并且是"True"不是“true”,是“False”不是"false"
- 11 回答
- 0 關(guān)注
- 510 瀏覽
添加回答
舉報(bào)
0/150
提交
取消