jquery – 如果URL包含阿拉伯字符,则Ajax在IE中不起作用

前端之家收集整理的这篇文章主要介绍了jquery – 如果URL包含阿拉伯字符,则Ajax在IE中不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的Blogger网站中,我从 JSON Feed加载帖子,JSON链接如下所示.
http://technopress-demo.blogspot.com/Feeds/posts/default/-/LABEL NAME?alt=json-in-script&max-results=5

这是我用来从上面的URL获取帖子的代码.

$.ajax({url:""+window.location.protocol+"//"+window.location.host
    +"/Feeds/posts/default/-/"+LABEL NAME
    +"?alt=json-in-script&max-results=5",type:'get',dataType:"jsonp",success:function(data){}

问题是当我用阿拉伯语标签更改’LABEL NAME’时,帖子没有加载.我用英文标签测试它,它工作正常,但我有阿拉伯语的问题.我试过这个解码URL,但它不起作用.

$.ajax({url:""+window.location.protocol+"//"+window.location.host
    +"/Feeds/posts/default/-/"+encodeURIComponent(LABEL NAME)
    +"?alt=json-in-script&max-results=5",success:function(data){}

这是一个live demo的问题.

解决方法

IE存在未正确编码的URL的问题,它还存在简单的< a href包含未编码的字符的问题. 标签名称而不是标签名称应该有效. 使用JSONP,jQuery生成一个< script src =“http://technopress-demo.blogspot.com/Feeds/posts/default/-/LABEL NAME?alt = json-in-script& max-results = 5”&gt ;里面有未编码的字符. 使用引号代替encodeURIComponent(LABEL NAME):
encodeURIComponent("LABEL NAME")

重要提示:保存UTF-8编码的文件.

(图片来自blog.flow.info)

在IE中运行的示例(从Firefox Firebug复制):

原文链接:https://www.f2er.com/jquery/178380.html

猜你在找的jQuery相关文章