Chrome Extension : Cross Origin $.Post Request
I am trying to access posterous API , to POST some content to site via google chrome extension ( and otherwise ) .
Since it's a public API , so I expect it to allow everyone to post , but for some reason , it does'nt allow to post .
However everytime I get error .
Same error comes when I access it from browsers
here's the error when accessed via browser
http://localhost is not allowed by Access-Control-Allow-Origin
here's the error when accessed via chrome extension
XMLHttpRequest cannot load http://posterous.com/api/2/users/me/sites/primary/posts?api_token=vxgufysnzlDwmEtkbDbzHtxxBADsEFGr&email=***@gmail.com&password=***. Origin chrome-extension://maabelkjnhafpphacjecmcnkkmjndjgl is not allowed by Access-Control-Allow-Origin.
Here's the code :
$.ajax({
//type: 'GET',
url: 'http://posterous.com/api/2/users/me/sites/primary/posts?api_token=vxgufysnzlDwmEtkbDbzHtxxBADsEFGr&email=shahid1376@gmail.com&password=WHY_DID_YOU_PUT_YOUR_REAL_PASS',
// url:'http://posterou开发者_运维百科s.com/api/2/users/me/sites/primary/posts/public',
type : 'POST',
dataType: 'json',
crossDomain: true,
data: "{'title': 'test posterous'}",
contentType:'text/plain',
success:function result(data) {
alert("Call completed successfully");
}
Your manifest.json
file should have the two domains you're looking to use in the permissions:
"permissions": [
"http://*.posterous.com/",
"http://localhost/"
]
For what it's worth, I wouldn't include localhost
in your permissions
; rather, use the domain you plan to use in production and then use a hosts
line to redirect the domain to your own server. This will let you develop on your own server but won't force your users to allow permissions on localhost
which they might not expect.
精彩评论