I have one file json.js and one php function in php file .in json.js i want to check value returned by php function if value returned by function is 0 jquery should perform :$(':input').prop('disabled', true); otherwise nothing –
function loadJson (table, id) {
$.get("json-object.php", {'table': table, 'id':id}, function (data) {
console.log(data);
$.each(data, function (k, v) {
if ($('input[name="'+k+'"]').is('input[type="text"]')) {
$('input[name="'+k+'"]').val(v);
}
if($('select[name="'+k+'"]').val(v)){
get_input_value(k,v);
}
if ($('input[name="'+k+'"]').is('input[type="checkbox"]')) {
get_input_value(k,v);
}
console.log(k+' ==> '+v);
// Here I want to check condition of php function if value returned by fucntion is 0 it should perform :$(':input').prop('disabled', true); otherwise nothing //
});
}, 'json');
}
My php function:
function ronly($id) {
//$id=$_POST['noces'];
$sql = "SELECT COUNT(noces) FROM alterdetail WHERE noces = '$id'";
$sql.=';';
//echo "QUERY <br/>";
//echo $sql;
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
if($row['COUNT(noces)'] > 0)
{ echo "you can not alter data";
return 0;
}
else
{
echo " data new ";
return 1;
}
}
-
I want to check condition of php function if value returned by fucntion is 0 jquery should perform :$(':input').prop('disabled', true); otherwise nothinguser1464087– user14640872012年06月20日 07:55:57 +00:00Commented Jun 20, 2012 at 7:55
-
Is the return value from PHP added in the AJAX response somehow?Ja͢ck– Ja͢ck2012年06月20日 07:59:41 +00:00Commented Jun 20, 2012 at 7:59
2 Answers 2
You can't, as Javascript is client-side executed, and PHP is server-side executed ...
A "solution" would be to assign a Javascript variable into the PHP file that you'll read into the Javascript file, as variable are global.
Comments
Use jQuery if possible.
$('#result').load('ajax/test.php', function() {
alert('Function called');
});
Or try JQuery forms. Use a form to submit any data, and it'll give you the response as a text or JSon object.
http://jquery.malsup.com/form/#ajaxSubmit
Here is an example for you:
$('#anyForm').ajaxForm({
url: "process.php?proc=7",
dataType: 'html',
success: function(responseText) {
if(responseText == "0") {
$(':input').prop('disabled', true);
}
}
});