gpt4 book ai didi

javascript - 为什么这个 JSON 在 IE 中不起作用

转载 作者:行者123 更新时间:2023-11-28 10:16:10 26 4
gpt4 key购买 nike

它适用于 Chrome 和所有其他浏览器,但不适用于 IE,我在下面做了一个示例:

http://develop.davzy.com/test1.php

(谈论的是 IE 8,我不确定它在 9 中是否运行正常)

当我运行 JSON 请求时,我收到一条错误,指出需要对象。这发生在第 29 行。

<!DOCTYPE html> 
<html>
<head>
<title>Sandbox</title>
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
</head>
<script>

function search()
{
$.ajax({
url: 'http://davzy.com/cache/api/rarevalues.php?callback=?&search=' + $('input').val(),
cache: false,
dataType: 'json',
success: function(data, status, xhr) {
$('body').append('<br>' + data[0].name);
$('input').focus().val('');
}
});
}

</script>
<body>
<div>type test or rare or chair</div>
<input onkeydown='if(event.keyCode == 13) search();'>
<button onclick='search()'>Go</button>
</body>
</html>

这里是它返回的 JSON 示例(回调工作正常,忽略 ? this is from http://davzy.com/cache/api/rarevalues.php?callback=?&search=petal )

    ?([{"0":"18","id":"18","1":"Petal Patch","name":"Petal Patch","2":"75","parent":"75","3":"cache\/rare_values\/images\/petal_patch.gif","small_image":"cache\/rare_values\/images\/petal_patch.gif","4":"cache\/rare_values\/images\/large\/petal_patch.gif","big_image":"cache\/rare_values\/images\/large\/petal_patch.gif","5":"A little bit of outdoors indoors..","motto":"A little bit of outdoors indoors..","6":"0","displayorder":"0","7":"1_center cache\/rare_values\/images\/petal_patch_1.png\n1_left cache\/rare_values\/images\/petal_patch_2.png","interactiveimages":"1_center cache\/rare_values\/images\/petal_patch_1.png\n1_left cache\/rare_values\/images\/petal_patch_2.png","hcs":12.5,"throne":0.06,"credits":"25"},{"0":"685","id":"685","1":"Petals","name":"Petals","2":"28","parent":"28","3":"cache\/rare_values\/images\/petal_flurry.gif","small_image":"cache\/rare_values\/images\/petal_flurry.gif","4":"cache\/rare_values\/images\/large\/petal_flurry.gif","big_image":"cache\/rare_values\/images\/large\/petal_flurry.gif","5":"Romance is in the air. And so are rose petals apparently.","motto":"Romance is in the air. And so are rose petals apparently.","6":"0","displayorder":"0","7":"","interactiveimages":"","hcs":1.5,"throne":0.01,"credits":"3"}])

Strimp099 是正确的,我需要 header('content-type: application/json; charset=utf-8');让我的 IE 将其视为 JSON。谢谢!

最佳答案

Strimp099 是正确的,我需要 header('content-type: application/json; charset=utf-8');让我的 IE 将其视为 JSON。谢谢!

关于javascript - 为什么这个 JSON 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558999/

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