views:

70

answers:

1

Hi,

I think this is just an obvious problem that I can't spot because I've been staring at code too long today. I have this callback as part of a JQuery POST:

                        function(data){
                                if(data == 'yes') {
                                        $('div.done').show();
                                } else if(data != 'yes') {
                                        $('div.error').show();
                                        alert(data);
                                }
                        });

I get the error div shown, yet in the alert all I get is yes. Anyone got any pointers (as I said, I imagine it's some really obvious mistake that I've missed).

Thanks

+4  A: 

Debuggng 101:

function (data) {
    alert(escape(data));
    if (data == 'yes') {
        $('div.done').show();
    } else if (data != 'yes') {
        $('div.error').show();
        alert(data);
    }
});
epascarello
Thanks. That turned up `yes%0a`. Is that a line feed? Do you know how I could remove that, or even better stop PHP sending it? The only thing in my PHP file that sends anything is `echo 'yes';`.
hrickards
%0A is a line feed you can do a regular expression: data.replace(/\n+$/);
epascarello
Thanks. Any idea why that might be being sent?
hrickards
Hmm, for some reason I still have the same issue. `alert(escape(data));` still shows `yes%0a`.
hrickards
Don't worry, I forgot the `data =` bit in front. That fixed it, thanks!
hrickards
The reason PHP is sending an extra line feed is probably because you have whitespace after your closing `?>`. Delete the whitespace, or better yet, delete the entire closing tag (it's optional).
Casey Hope