Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax doesn't work in IE if URL contains Arabic character

In my Blogger website I load posts from JSON feed, The JSON link looks like this.

    http://technopress-demo.blogspot.com/feeds/posts/default/-/LABEL NAME?alt=json-in-script&max-results=5

This is the code that I use to get posts from the URL above.

    $.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){}

The problem is that when I change 'LABEL NAME' with an Arabic label the posts didn't load. I tested it with English label and it's working fine, but I have problem with Arabic ones. I have tried this to decode URL but it's not working.

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

This is a live demo of the problem.

like image 721
Masked Avatar asked May 10 '14 14:05

Masked


1 Answers

IE has problems with not properly encoded URLS, it has also problems with simple <a href containing unencoded chars.

LABEL%20NAME instead of LABEL NAME should work.

With JSONP, jQuery generates a <script src="http://technopress-demo.blogspot.com/feeds/posts/default/-/LABEL NAME?alt=json-in-script&max-results=5"> which has the unencoded char in it.

Instead of encodeURIComponent(LABEL NAME), use quotation marks:

encodeURIComponent("LABEL NAME")

Important: Save your files UTF-8 encoded.

enter image description here(pic from blog.flow.info)

Example which works in IE (copied from Firefox+Firebug):

enter image description here

like image 128
Daniel W. Avatar answered Oct 09 '22 16:10

Daniel W.