开发者

Using jquery in a facebook iframe application - GET vs. POST

I was wondering what needs to be considered when using jquery in an facebook iframe app.

I am trying to enable my grid to use paging without reloading the whole ASP.NET MVC page all the time.

Are there any special actions that need to be done when using jquery inside an facebook iframe app?

EDIT: I am already using jquery-ui components like datepicker which work fine. But as soon as i want want to inser开发者_开发知识库t the result of an Controller action in an Html element i struggle.

EDIT2: It seems that jquery functions using the POST protocol work fine but not when using the GET protocol.

Sample call:

Works:

       $("#element").live("click", function () {
   $.ajax(  
    {  
        type: "POST",  
        url: "<%=Url.Action("Action","Controller") %>",  
          parameters: {  page: 2  },
        success: function(result) {  
            $("#element2").html(result); 
        }  
    });  

       return false;
   });

Does not work:

       $("#element").live("click", function () {
   $.ajax(  
    {  
        type: "GET",  
        url: "<%=Url.Action("Action","Controller") %>",  
          parameters: {  page: 2  },
        success: function(result) {  
            $("#element2").html(result); 
        }  
    });  

       return false;
   });


I am already using jquery-ui components like datepicker which work fine. But as soon as i want want to insert the result of an Controller action in an Html element i struggle.

You can insert the result of a controller action into an HTML element using the jQuery function getJSON, see this reference document for more info.

You Controller Action should return a JsonResult object.

For example, this jQuery code calls an Action (myAction) on a Controller (myController), and updates an HTML element with a property of the returned object:

$.getJSON('MyWebsite/MyController/MyAction', SomeParameters, function (result) {
    if (result!=null)
    {
        $('#MyElement').html(result.Value1);
    })

And your controller action should return a JsonResult object like this:

public JsonResult MyAction()
{
    return Json(new SomeObject
        { Parameter1 = Value1}, JsonRequestBehavior.AllowGet);
}

Hope this helps.


No special actions need to be done: the contents of the iframe are entirely under your control. You can load any javascript files you want in the iframe, and perform any actions on your code. I've used jquery in Facebook iframe apps extensively. The key thing to note is that the iframe content is just another web page. You can do anything in there you can do in a regular web page (except maybe change the window size: that's a pain, but can still be done wtih the Facebook SDK).

If you need to access the Facebook API, the Facebook Javascript SDK is your friend, but within the iframe you can do anything you could do on a regular web page.


I think you can't.

For security reasons javascript between two iFrames (parent / child) is disabled by browsers if they are not on the same domain. So www.yourwebsite.com can't call javascript functions from www.facebook.com when facebook.com is in a iFrame for example (stupid example but it can help you to make it clear)

I think you are stuck with calling services

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜