javascript - question about functions in php -
i have php file 2 function
<?php function first () { //in real case more conditions echo "first"; return true; } function second () { //in real case more conditions echo "second"; return true; } first(); second(); ?> and in ajax file
function(data) { if (data == "first") { $("#msgbox1").fadeto(200, 0.1, function() { $(this).html('something'); }); } else if (data == "second") { $("#msgbox1").fadeto(200, 0.1, function() { $(this).html('something else'); }); } the problem because php devolve firstsecond , need check in individual mode - first , second. if make return first; how can check in data if return correct? data==first not working
thanks
you'd want more along these lines:
function first() { if (some condition ...) { return true; } return false; } function second() { if (some other condition...) { return true; } return false; } $data = array(); $data['first'] = first(); $data['second']= second(); echo json_encode($data); then in javascript code:
if (data.first) { ... first occurred } if (data.second) { ... second occured; } must better return actual javascript data structures via json encoding, string. way can pass in other data elements. instance, if first() doing database lookup , blew up, can return 'false' along error message indicating why request failed.
Comments
Post a Comment