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.

    评论

报告相同问题?