我想知道在 facebook iframe 应用程序中使用 jquery 时需要考虑什么。
我正在尝试使我的网格能够使用分页,而无需始终重新加载整个 ASP.NET MVC 页面。
在 Facebook iframe 应用程序中使用 jquery 时是否需要执行任何特殊操作?
编辑:我已经在使用像 datepicker 这样的 jquery-ui 组件,它工作得很好。但一旦我想将 Controller 操作的结果插入 Html 元素中,我就会陷入困境。
编辑2:似乎使用POST协议(protocol)的jquery函数工作正常,但在使用GET协议(protocol)时则不然。
调用示例:
作品:
$("#element").live("click", function () {
$.ajax(
{
type: "POST",
url: "<%=Url.Action("Action","Controller") %>",
parameters: { page: 2 },
success: function(result) {
$("#element2").html(result);
}
});
return false;
});
不起作用:
$("#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.
您可以使用 jQuery 函数 getJSON
将 Controller 操作的结果插入到 HTML 元素中,请参阅 this reference document了解更多信息。
您的 Controller 操作应该返回一个 JsonResult
对象。
例如,此 jQuery 代码在 Controller (myController) 上调用操作 (myAction),并使用返回对象的属性更新 HTML 元素:
$.getJSON('MyWebsite/MyController/MyAction', SomeParameters, function (result) {
if (result!=null)
{
$('#MyElement').html(result.Value1);
})
您的 Controller 操作应该返回一个 JsonResult
对象,如下所示:
public JsonResult MyAction()
{
return Json(new SomeObject
{ Parameter1 = Value1}, JsonRequestBehavior.AllowGet);
}
希望这有帮助。
关于jquery - 在 facebook iframe 应用程序中使用 jquery - GET 与 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5870920/