PHP Jquery JSON捕获

Here's my php responding to my jQuery calls.

<?php



if ( isset( $_POST['icnumber']) && $_POST['icnumber'] != '' ) {
    $custic = $_POST['icnumber'];
    $response = array();
    $response['status'] = 'false';
    $sql ="SELECT * FROM ctrl_cust WHERE cust_ic='$custic'";
    $raw = mysql_query($sql,$link) or die('Query 1 '.mysql_error());
    if ( $data = mysql_fetch_assoc( $raw ) ) {
       $response['status'] = 'true';
       $response['custid'] = $data['cust_id'];
       $response['custname'] = $data['cust_name'];
    }
    header("Content-Type: application/json", true);
    echo json_encode($response);    
}
?>

and here's the jQuery

$(function() {
    $('#icnumber-form').submit(function() {       

       var icno  = $('#icnumber').val();

       $.ajax({
           type    : 'POST',
           url     : 'php/create_process.php',
           data    : icno,
           dataType: 'json',
           success : function(data){
               console.log(data);             
           },
           beforeSend:function(){
               $('.cust-exist-view').fadeIn();
           }
       });
       return false;
    })
});

The thing is, console.log returns NULL, but when I submit the form without javascript enabled, it returns this :

{"status":"true","custid":"00001","custname":"John"}

I wonder what is the problem...I've been running around in circles for hours...Help me please?

查看全部
weixin_33738982
?Briella
2013/07/22 05:36
  • json
  • php
  • ajax
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

1个回复