Thursday, January 12, 2012

JQuery success callback isn't being called or?


I have searched a lot of threads but i can't find any answer that suits me. Now I will try to explain my problem.



I have a simple jQuery script that does a little ajax request. its simple like this:




print("
<script>
function buscaCaracteristicas(idTotalizador){
var target = '../../ajax/doSomeSearch.php';
$.ajax({
url: target,
//dataType: 'html',
dataType: 'text',
type: 'POST',
success: function(msg){
alert(msg);
}
});
}
</script>
");



And the PHP page does this:




<?php
$ret = "<p>hello world</p>";
exit($ret);
?>



I have tried putting the return data on an HTML element via $.html(msg) too. Problem is: alert or the $.html() on callback NEVER fires although on firebug I can check the request has the return code 200 OK.



Notice that the function code is wrapped into a PHP print("") command and the return dataType is HTML which is what I really need to get (can't use JSON).



Any miraculous advice? Thanks in advance.



Solved: changing dataType to 'text' according to Splash-X advices it worked.

No comments:

Post a Comment