$.post() not working in IE
I creating a fb app. I use FB.ui method apprequests to select friends to whom I send also want to post to wall. This looks like this.
<div id="fb-root"></div>
<script src="http://connect.facebook.net/pl_PL/all.js" type="text/javascript"></script>
<script type="text/javascript" >
FB.init({
appId: myappID,
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
channelUrl : 'http://localhost:3435/Content/channel.html'
});
function invite(){
FB.ui({ method: 'apprequests',
message: 'You should learn more about this awesome game.',
data: 'tracking information for the user'
},
function (response) {
if (response && response.request_ids) {
len = response.request_ids.length; //# of reqs
var i = 0;
for (i = 0; i < len; i++) {
user_req_id = response.request_ids[i];
FB.api('/me/apprequests/?request_ids=' + toString(user_req_id),
function (response) {
$.post("http://localhost:3435/Home/PostToWall",
{ request_ids: response['data'][0]['from']['id'] },
function (data) { alert("Data Loaded: " + data); }
);
});
}
} else {
// alert('Post was not published.');
}
})
};
</script>
As you can see I'm want to do a post request to a
[HttpPost, CanvasAuthorize(Permissions = "user_about_me,publish_stream,email")]
public ActionResult PostToWall(string request_ids)
{
/* Post to Wall Logic */
return View();
}
This works fine with Chrome and Firefox, but in IE the Action isn't fired up.
I prepared a small sample javascript, which you can test. This is where the problem seems to be.
<script type="text/javascript" >
function CallPostToWall() {
$.post("http://localhost:3435/Home/PostToWall",
{ request_ids: 100001968250722 },
function (data) { alert("Data Loaded: " + data);}
);
};
</script>
<a href='#' onclick='CallPostToWall()'>Test Posting</a>
When this is tested in FF and Chrome, the alert return the actions expected html as if http://localhost:3435/Home/PostToWall?request_ids=100001968250722 was requested.
In IE on the other hand. I get somethin like:
<html><head><script type="text/javascript">
top.location = "http://www.facebook.com/dialog/oauth/?scope=user_about_me,publish_stream,email&state=eyJyIjoiaHR0cDovL2FwcHMuZmFjZWJvb2suY29tL2NoaW5jenlrd3Nvc2llL0hvbWUvUG9zdFRvV2FsbCJ9&a开发者_Python百科mp;client_id=248066421875572&redirect_uri=http://localhost:3435/facebookredirect.axd";
</script></head><body></body></html>
I pretty lost with this.
Any thoughts?
Regards, Simon
Finally! I solved my problem which is because of "same origin policy" and just raise in IE!: I've just change the URL parameter from : 'http://mysite.com/api/' to '/api/' and it works!!!
hope it help some of you!
Perhaps this is just a workaround. I've managed to get the $.post() running/returning the correct view by removing the CanvasAuthorize(...) attrinbute from the PostToWall definition
[HttpPost]
public ActionResult PostToWall(string request_ids)
{
/* Post to Wall Logic */
return View();
}
As I understood, after reading a couple of posts on the web, this might be caused by IE preventing "cross-site-scripting"-like actions.
精彩评论