Yud*_*ira 1 ajax jquery types response
我有这个代码
// jquery
$(document).ready(function() {
$('#update_point').live("change", function() {
var point_val = $('#update_point').val();
$.ajax({
url: 'send/user/update_point.php',
type: 'get',
data: 'point='+point_val,
dataType: 'json',
success: function(data){
alert(data);
$('#update_point_result').html(data);
}
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
为什么那段代码没有被解雇?但如果我删除dataType,代码可以工作.为什么?
// jquery
$(document).ready(function() {
$('#update_point').live("change", function() {
var point_val = $('#update_point').val();
$.ajax({
url: 'send/user/update_point.php',
type: 'get',
data: 'point='+point_val,
success: function(data){
alert(data);
$('#update_point_result').html(data);
}
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将是appreaciate它!谢谢 !
编辑
update_point.php包含此代码.
<?php
require "../../inc/json.php";
if($_GET){
foreach($_GET as $key=>$val){
$respon[$key] = $val;
}
}
// initialitation json object
$json = new Json();
echo $json->encode($respon);
die();
?>
Run Code Online (Sandbox Code Playgroud)
$.ajax当JSON形成错误时,他们喜欢默默地失败.使用jsonlint等工具检查服务器中的JSON是否格式正确.
您可以使用.error回调来检查抛出的错误类型:
$.ajax({
url: 'send/user/update_point.php',
type: 'get',
data: 'point='+point_val,
success: function(data){
alert(data);
$('#update_point_result').html(data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown); // likely 'parseError'
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1358 次 |
| 最近记录: |