getJSON方法的一个使用困惑

Java代码 复制代码 收藏代码
  1. var url = "deal/can_vote.jsp";   
  2.                 $.getJSON(url,{"cmplt_detail_id":cmplt_detail_id},function(data){   
  3.                     var temp = data.data;   
  4.                     if(temp=="0"){   
  5.                         alert("已足够票数,不能再投了");   
  6.                     }else if(temp=="00"){   
  7.                         alert("你已投过票,不能再次投票了");   
  8.                     }   
  9.                 })  

点击“确定”按钮,执行这段代码,发现getJSON方法只有在第一次请求时才会访问后台。以后都不会访问后台了,除非新开一个窗口。
由于在投票过程中,要时刻监控票数,所以需要每次点击“确定”的时候都能与后台交互。知道数据库里面的票数是多少。
用$.post() 或 $.get() 是可以每次与后台交互,但却不知如何得到JSON串
有什么好的解决办法吗

问题已解决,
把 $.getJSON方法改成$.post方法
比如

$.post(url,{"cmplt_detail_id":cmplt_detail_id},function(data){
      var temp = data.data;
      if(temp=="0"){
      alert("已足够票数,不能再投了");
     
      }else if(temp=="00"){
      alert("你已投过票,不能再次投票了");
            }
      },"json")
即可。post方法的"json"是关键

posted on 2012-07-30 09:02  babyblue  阅读(119)  评论(0)    收藏  举报