March 4, 2012

Jquery $.ajax not returning correctly, but does for someone else

Question by user1247901

jquery:

var value="value"
var datastr="data"+value;
 $.ajax({
        type:'POST',
        url:'ggg.php',
        data: datastr,
        dataType: "html",
        success:function(response) {
            $("#task").html(response);
        }
        });

});

php:

echo 'this is your response';

The variables are just there to show what I would do if I were using them. It should be returning “this is your response”, but i’m getting “jtftcyrxcktfitdkfkf”. I’m not sure what is causing this, I’ve tried changing the dataType, etc. Someone else used the code as is, and said it is returning correctly for them. So is there anything that would be causing it not to work correctly for me? :/

Answer by Starx

I think your script is giving that jtftcyrxcktfitdkfkf somewhere in ggg.php. Have you included or required some file before/after. Make sure they are not returning any output.

When all hope seems to fail, clear the output buffer

ob_clean();
echo 'this is your response';
exit;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!