-5
有人可以幫助我使用jquery接收此json嗎?接收與jQuery的json?
{
"output_type":"json","diagnostic":{"status":"200","elapsetime":"0.4187","memoryusage":"17.91MB","confirm":"success","lang":"id","currency":"IDR"},"results":{"result":[{"id":"business:3772","label":"Puri Maharani Boutique Hotel & Spa - Denpasar, Denpasar Timur, Kesiman Kertalangu","value":"Puri Maharani Boutique Hotel & Spa","category":"Hotel"},{"id":"business:3852","label":"Maharani Hotel - Jakarta Selatan","value":"Maharani Hotel ","category":"Hotel"},{"id":"business:3874","label":"Maharadja Hotel - Jakarta Selatan, Mampang Prapatan, Tegal Parang","value":"Maharadja Hotel","category":"Hotel"},{"id":"business:4776","label":"Pita Maha Resort and Spa - Gianyar, Ubud, Ubud","value":"Pita Maha Resort and Spa","category":"Hotel"},{"id":"business:4779","label":"The Royal Pita Maha Resort and Spa - Gianyar, Ubud, Kedewatan","value":"The Royal Pita Maha Resort and Spa","category":"Hotel"},{"id":"business:18420","label":"Villa Mahapala Bali - Denpasar, Denpasar Selatan, Sanur","value":"Villa Mahapala Bali","category":"Hotel"},{"id":"business:105246","label":"Mahagiri Dreamland Villas & Spa - Badung, Kuta Selatan, Pecatu","value":"Mahagiri Dreamland Villas & Spa","category":"Hotel"}]},"token":"bc8d3a106572e4cff038261afb568ecf"}
我使用$ .getJSON和$ .ajax函數,但發生了一些問題,有人可以幫我一些jQuery代碼嗎?
這是我的代碼,
function getAPI() {
jQuery.ajax({
url: 'http://api.master18.tiket.com/search/autocomplete/hotel?q=mah&token=90d2fad44172390b11527557e6250e50&secretkey=83e2f0484edbd2ad6fc9888c1e30ea44&output=json',
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
type:"get",
dataType: 'json',
crossDomain: true,
success: function(data) { console.log(data); }
});
}
但錯誤是未捕獲的SyntaxError:意外的標記:
出現什麼問題?分享更多的JavaScript代碼。就像ajax呼叫一樣。 –
其實,我試試這個代碼.. 功能getAPI(){ \t \t jQuery.ajax({ \t網址:「http://api.master18.tiket.com/search/autocomplete/hotel?q=麻將&標記= 90d2fad44172390b11527557e6250e50&祕密密鑰= 83e2f0484edbd2ad6fc9888c1e30ea44&輸出= JSON」, \t \t beforeSend:函數(X){ \t \t如果(X && x.overrideMimeType){ \t \t x.overrideMimeType(「應用程序/ JSON;字符集= UTF- 8「); \t \t} \t \t}, \t類型: 「獲取」, \t數據類型: 'JSON', \t跨域:真, \t成功:功能(數據){的console.log(數據); } \t \t}); \t} –
對不起,我將編輯我的代碼 –