почему этот jquery не вызовет запрос .ajax ()? - PullRequest
1 голос
/ 16 июля 2011

у меня есть этот код

// 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;
    });
});

почему этот код не сработал? но если я удаляю 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;
    });
});

любая помощь будет оценена! Спасибо!


1010 * редактировать *

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();
?>

1 Ответ

5 голосов
/ 16 июля 2011

$.ajax любит молча терпеть неудачу, когда JSON плохо сформирован. Проверьте, правильно ли сформирован JSON с сервера, используя такой инструмент, как jsonlint .

Вы можете использовать обратный вызов .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'
        }
 });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...