I hava a PHP script which generates a PDF file (i’m using fpdf from http://www.fpdf.org). I’m calling the PHP from an html using AJAX $.post(…..). When submit button is clicked, the span shows ‘please wait…’. The PDF is getting generated but still the span shows ‘please wait…’. The span is not getting updated. Below is the code for AJAX call:
$(document).ready(function()
{
$("#genByDt").submit(function()
{
$("#msg").text('Please wait....').fadeIn(1000);
var otherValidations = validate(document.genByDt);
if(otherValidations == false)
{
return false;
}
else
{
$.post("/pawn/fpdf/chittiCode/generateChitti.php",{ whichSubmitted:$('input[name = whichSubmitted]').val(), dateSelected:$('input[name = dateSelected]').val() }, function(data){
var obj = $(data);
if($.trim($(obj,'body').text()) == 'success')
{
$("#msg").fadeTo(200,0.1,function(){
$(this).text('Bills generated successfully !!').fadeTo(900,1);
$('input[name = dateSelected]').val('');
});
}
else if($.trim($(obj,'body').text()) == 'zeroBills')
{
$("#msg").fadeTo(200,0.1,function(){
$(this).text('No bills for the selected date !!').fadeTo(900,1);
$('input[name = dateSelected]').val('');
});
}
});
return false; //not to post the form physically
}
});
});
I know the problem is in the IFcondition. The PHP is returning a string but the $(data) is of type object[ I found this by using alert(obj); ]. Below is a part of the PHP:
if($success == 1)
{
echo "success";
}
else
{
echo "zeroBills";
}
If the PHP is returning a string, then
datawill be a string and should be treated as such:(You mentioned you found the type of
objby sayingalert(obj); what happens if you sayalert(data)?)