jQuery ajax json解析错误

when i pass ajax values it says json parseererror, tried jsonp but not working. Here's my code:

HTML:

<form class="ajaxform" method="post">
    <div class="form-group form-inline">
        <label for="searchtxt">Search Here: </label>
        <input type="text" name="ajaxinput" class="form-control ajaxinput">
    </div>
    <div class="form-group">
        <a href="" class="ajaxsubmit btn btn-primary">Get Data</a>
    </div>
</form>

PHP:

$return_array = array();

$query = "select * from tbl_admin where uName like '%".$ajaxinput."%' or uEmail like '%".$ajaxinput."%'";

$abc = $db->pdoQuery($query)->results();

foreach ($abc as $key => $value) {
    # code...
    $return_array['admin_name'] = $value['uName'];
    $return_array['admin_email'] = $value['uEmail'];
    $return_array['admin_ip'] = $value['ipAddress'];

    echo json_encode($return_array);
}
exit();

JQUERY:

$('.ajaxsubmit').on('click', function(e){  
e.preventDefault();
var urlPath = siteName+'modules-nct/ajax-nct/ajax.ajax-nct.php';
var mydata = jQuery(".ajaxform").serialize();

$.ajax({
url: urlPath,
data : mydata,
dataType: 'json',

success: function(response){
  console.log(response);
  alert(response);

},
error: function(xhr, status){
  console.log(status);
}
});
});

i want data in json as i have to append it in a table. In datatype: html data comes but not that useful as it contains multiple records.

查看全部
weixin_33712987
weixin_33712987
2018/01/29 07:40
  • json
  • php
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

1个回复