gpt4 book ai didi

javascript - Jquery 自动完成 json 数据

转载 作者:行者123 更新时间:2023-12-02 16:10:14 25 4
gpt4 key购买 nike

我有一个奇怪的问题:

首先我有这个代码:

var countries = dajjson();

$('#usluga').autocomplete({
lookup: countries,
onSelect: function (suggestion) {
alert('You selected: ' + suggestion.ID + ', ' + suggestion.naziv);
}
});
});

function dajjson() {
$.ajax({
url: "autoUsluge.php",
type: "POST",
async: true,
dataType: "html",

success: function(data) {
console.log(data);
},
error: function (data) {
console.log(data);
console.log('GRESKA NEKA');
}
});
};

我的 JSON 是 - 函数 DAJJSON() 返回:

[{"ID":"4","naziv":"","opis":"Web dizajn","jmere":"komada","kol":"2","cena":"50","valuta":"Eur","popust":"5","porez":"20","user_id":"1"},{"ID":"5","naziv":"","opis":"Programiranje","jmere":"sati","kol":"5","cena":"10","valuta":"Eur","popust":"5","porez":"20","user_id":"1"},{"ID":"6","naziv":"","opis":"Popravka zadnjeg trapa na automobilu Audi","jmere":"komada","kol":"1","cena":"80","valuta":"Eur","popust":"5","porez":"20","user_id":"1"}]

以及我在哪里测试刚刚得到的代码:

Uncaught SyntaxError: Unexpected token <

最佳答案

在您使用的任何浏览器中打开开发人员工具(通常是 F12 或 Ctrl-Shift-I 或在菜单中的某个位置)。单击“网络”选项卡并运行您的代码。

查看对 AJAX 请求的响应。这不会是你所期望的:)

您传递给 AJAX 的 dataType 属性告诉服务器您期望的数据类型。您将其设置为 html,因此您的响应将采用 HTML 格式。从表面上看,您确实需要 json

关于javascript - Jquery 自动完成 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30290229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com