weixin_33738578 2016-04-22 19:14 采纳率: 0%
浏览 24

jQuery ajax结果数据

I'm having trouble using the return data within my ajax call. What is the best way to go about this?

I simply send information to checker.jsp. It computes it. If the check is good, it responds with a Green. If it's bad, it responds with a Red.

If I use this within the success:

alert(light_color);

I get what seems to be the entire web page with the word "Red" 40 lines down. Because of this the if and elses do not work. I want to use the result and only the result. Not the html and everything in it.

What am I doing wrong?

Any help would be appreciated!

 $.ajax({
        type: 'POST',
        url: 'checker.jsp',
        data: {
            'bank_cnt': bank_cnt
        },
        success: function (result) {
            var light_color = result;
            if (light_color === 'Red') {
              alert('Red');  
            } else if (report === 'Green') {
                alert('Green');
            } else {
                alert('didnt work');
            }
        }
    });
  • 写回答

3条回答 默认 最新

  • weixin_33739541 2016-04-22 19:29
    关注

    I want to use the result and only the result. Not the html and everything in it.

    The 'result' has 'the html and everything in it'. You will need to modify checker.jsp to only send 'Red' or 'Green' and also set the content-type in the header of the response to text. You should investigate how to respond to requests in JSON format.

    评论

报告相同问题?

悬赏问题

  • ¥15 求一个图片中的成交量选股公式
  • ¥30 关于#python#的问题:我想要的是这79个大特征对于房屋售价的最大的影响前十名(相关搜索:随机森林)
  • ¥15 使用matlab计算自定义特殊函数的二重积分,改变积分顺序所得的结果不同的问题?
  • ¥15 mysql做碎片化处理老是报错怎么办
  • ¥15 如何正确在vs2010中初始化map对象
  • ¥30 mmdet3d模型部署问题
  • ¥15 comsol仿真反射率、吸收率时峰值位置和深度不对!
  • ¥30 Visual Studio找不到sdk,如何解决?
  • ¥15 labview与机器之间网口通信发送指令
  • ¥15 迪杰斯特拉算法,考虑时延,带宽