I need a help with the below-given function. The function mainApp.php returns 1, but Else part of the success IF statement is executed. I have doubts regarding the correctness of an expressionfunction(html,msg). How to solve this problem?
UPDATE (Working code):
function click_function_ps() {
$.ajax({
url: 'callpage.php?page=optim/mainApp.php',
data: 'myParam='+$('#myParam').val(),
dataType: 'json',
success: function(output){
if(output.msg === 1){
$('#myContainer').html(output.html);
} else {
$dialog.dialog('open');
return false;
}
}
});
}
mainApp.php
$html_code = '<table width="100%">
<tr>
<td width="100%">
<div class="scrollbar" id="chart"><img class="displayed" src="ganttchart.php"></div>
</td>
</tr>
</table>';
echo json_encode(array('msg' => 1, 'html' => $html_code));
The response returned is in the first argument. The second one is usually not interesting.
I’d also suggest you to rename
htmlto something more meaningful such asdataorresponseand adddataType: 'json'to your ajax arguments. Then make your PHP script returnjson_encode(array('msg' => 1, 'html' => $your_html_code))and usedata.msganddata.htmlin your function.