且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSON解析错误:JSON数据第1行第1列的数据意外结束

更新时间:2022-04-09 04:24:36

jQuery.load 是异步,您正在尝试在JSON实际加载之前对其进行解析.使用 jQuery.getJSON 加载内容,进行解析并提供可绑定到的回调

jQuery.load is asynchronous, you're trying to parse the JSON before its actually loaded. Using jQuery.getJSON loads the content, does the parsing and provides a callback you can bind to.

jQuery.load将内容加载为HTML并设置所选元素的innerHTML,您也可以在此处绑定complete处理程序,但是通过将内容加载为HTML然后使用从DOM检索它,因为JSON的某些部分可能被解释为HTML元素.

jQuery.load loads the content as HTML and sets the innerHTML of the selected element, you could bind the complete handler here aswell, but you may encounter issues by loading the content as HTML and then using text to retrieve it from the DOM as some parts of your JSON may be interpreted as HTML elements.

***使用这个:

$(document.body).on('change', '.select' , function () {
    var identification = $(this).val();
    $.getJSON(
        'analysis.php?data=' + identification + ' #data',
        function (data) {
           console.log(data);
        }
    );
});