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.
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.
(pic from blog.flow.info)
Example which works in IE (copied from Firefox+Firebug):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With