SyntaxError:从php接收JSON时,JSON输入意外结束
我试图使用JQUERY在表中显示MySQL数据库中的一些数据,因此我编写了以下代码:SyntaxError:从php接收JSON时,JSON输入意外结束,php,jquery,mysql,json,ajax,Php,Jquery,Mysql,Json,Ajax,我试图使用JQUERY在表中显示MySQL数据库中的一些数据,因此我编写了以下代码: $(document).ready(function () { $("#a1<?=$com->code_fournisseur?>").click(function () { $("#tab1<?=$com->code_fournisseur?>").show(); $("#tab2<?=$com->code_fourni
$(document).ready(function () {
$("#a1<?=$com->code_fournisseur?>").click(function () {
$("#tab1<?=$com->code_fournisseur?>").show();
$("#tab2<?=$com->code_fournisseur?>").hide();
$("#tab3<?=$com->code_fournisseur?>").hide();
$("#tab4<?=$com->code_fournisseur?>").hide();
$.ajax({
type: 'POST',
dataType: "json",
processData: false,
url: 'fournisseur.php',
data: {'id_f': <?=$com->code_fournisseur?> , 'type': 'article_f'},
success: function (response) {
for (var i = 0; i < response.length; i++) {
$("#tab1<?=$com->code_fournisseur?>").html(response[i]["id_article_interne"]);
// just to see some result
}
},
error: function (xhr, status, error) {
//var err = JSON.parse(xhr.responseText) ;
//alert();
console.log(xhr.responseText + " " + error);
//alert(error);
}
});
});
但我得到了这个错误信息:
SyntaxError:JSON输入意外结束
我做了一个测试,看看我的php是否不正确:它给了我这个JSON:
[{
"fourn_code": "F00141",
"code_article": "1",
"designation": "crayon",
"id_article_interne": "10 Kgs de ciments",
"prix": "0.00",
"remise": "0.00",
"taux_tva": "10.00",
"disponible": "Disponible",
"qte_cdes": "0.00"
}, {
"fourn_code": "F00141",
"code_article": "mg",
"designation": "JEUX",
"id_article_interne": "jeux educatifs pratique \"le corps humain\"",
"prix": "6000.00",
"remise": "0.00",
"taux_tva": "20.00",
"disponible": "Disponible",
"qte_cdes": "0.00"
}]
你能帮我吗?正确设置你的帖子的格式。如果你最终处于
catch
状态,你没有返回JSON,这只是一个错误,你的ajax请求将失败,因为它没有接收到echo“”的有效JSONcheck输出;印刷品(文章)在json\u encode()
之前进行编码,看看接下来会发生什么。您完全可以进行SQL注入。既然您正在使用PDO,请利用and或。这将解决可能出现的任何令人讨厌的引用问题。这是我从打印($articles)中得到的:数组([0]=>stdClass对象([fourn\u code]=>F00141[code\u article]=>1[designation]=>crayon[id\u article\u interne]=>10千克材料[prix]=>0.00[remise]=>0.00[tauTVA]=>10.00[disponsible]=>10.00[qte\u cdes]=>0.00)[1] =>stdClass对象([fourn\u code]=>F00141[code\u article]=>mg[designation]=>JEUX[id\u article\u interne]=>JEUX教育实践“le corps humain”[prix]=>6000.00[remise]=>0.00[taux\u tva]=>20.00[Disponsible]=>Disponsible[qte\u cdes]=>0.00))正确格式化您的帖子。如果您最终处于catch
状态,您没有返回JSON,这只是一个错误,您的ajax请求将失败,因为它没有收到echo”“;print_r($articles);
beforeJSON_encode()的有效JSONcheck输出
看看会发生什么。你对SQL注入非常开放。因为你正在使用PDO,利用and或。这将解决可能出现的任何令人讨厌的引用问题。这是我从print_r($articles)获得的结果:数组([0]=>stdClass对象([fourn_code]=>F00141[code_article]=>1[designment]=>crayon[id_article_interne]=>10千克重量[prix]=>0.00[混合]=>0.00[可分配]=>10.00[可分配]=>0.00[1]=>stdClass对象([fourn_代码]=>F00141[代码文章]=>mg[名称]=>JEUX[身份证]文章内部]=>JEUX教育实践“le corps”[prix]=>6000.00[可分配]=>0.00[可分配]=>可争议[qte_cdes]=>0.00)
[{
"fourn_code": "F00141",
"code_article": "1",
"designation": "crayon",
"id_article_interne": "10 Kgs de ciments",
"prix": "0.00",
"remise": "0.00",
"taux_tva": "10.00",
"disponible": "Disponible",
"qte_cdes": "0.00"
}, {
"fourn_code": "F00141",
"code_article": "mg",
"designation": "JEUX",
"id_article_interne": "jeux educatifs pratique \"le corps humain\"",
"prix": "6000.00",
"remise": "0.00",
"taux_tva": "20.00",
"disponible": "Disponible",
"qte_cdes": "0.00"
}]