0

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;
                }
   }    
2
  • I want to check condition of php function if value returned by fucntion is 0 jquery should perform :$(':input').prop('disabled', true); otherwise nothing Commented Jun 20, 2012 at 7:55
  • Is the return value from PHP added in the AJAX response somehow? Commented Jun 20, 2012 at 7:59

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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); 
        }
    } 
});

2 Comments

what is sellform here ? process.php is the file where i have my php function . data type should be html ok . in success can i use my condition in place of function ?
#sellForm is a <form>. You can do: if(responseText === 0) { $(':input').prop('disabled', true); } instead the alert. If that's what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.