why this jquery won't trigger .ajax() request?
i have this code
// 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;
});
});
why that code doesn't fired ? but if i'm remove dataT开发者_开发百科ype, the code works. why ?
// 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;
});
});
any help will be appreaciate it ! Thanks !
edit
update_point.php contains this code.
<?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();
?>
$.ajax
likes to silently fail when JSON is badly formed. Check that the JSON from the server is well formed, using a tool such as jsonlint.
You can use the .error
callback to check the type of error being thrown:
$.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'
}
});
精彩评论