what this json must work?

Posted by user1772630 on Stack Overflow See other posts from Stack Overflow or by user1772630
Published on 2012-10-31T04:57:50Z Indexed on 2012/10/31 5:00 UTC
Read the original article Hit count: 86

Filed under:
|
|
|

hi i search alot for get a respone from php back and if that respone is ok do someting and if its false do something else(!!!!!!!! WHENE I HAVE OTHER OUTPUT FROM THAT PHP !!!!!!) this is my index file

<head>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script src="js.js" type="text/javascript"></script>
</head>
<body>
<p> click </p>
<input type="text" id="who">
<br>
<input type="text" id="why">
<div id="bg" align="center">
</div>
</body>

this is my JS file

$(document).ready(function(){
    $('p').click(function(){
        var who = $('input#who').val();
        var why = $('input#why').val();     
        $.post('file.php',{who:who,why:why},function(data) {
    if(data.success){
         alert(data.message);
    }
    else{ alert('ERROR:' + data.message);
    }
});




    });
});

and this is my file.php

<?php
$response = array('success' => 'true', 
    'code' => "jQuery('#bg').html('\"Javascript\", \"json\", \"PHP\"');");
echo json_encode($response);
?>

my question : 1- why this is not work i get alert (error:undifined) 2- how i can get some result from that php file when its have other output like this:

<?php
echo "1";
echo "2";
echo "3";
and now echo that json
?>

thanks :(

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript