Javascript 如何在iframe on ajax调用中加载部分视图?
我正在使用MVC 4,并尝试使用$.ajax调用在iframe中加载部分视图,如下所示:Javascript 如何在iframe on ajax调用中加载部分视图?,javascript,jquery,ajax,asp.net-mvc,iframe,Javascript,Jquery,Ajax,Asp.net Mvc,Iframe,我正在使用MVC 4,并尝试使用$.ajax调用在iframe中加载部分视图,如下所示: $(document).ready(function () { $("#btnInsert").click( function(e) { e.preventDefault(); var loc = window.location.href; loc = (loc.substr(loc.length - 1, 1) == "/") ? loc
$(document).ready(function () {
$("#btnInsert").click(
function(e) {
e.preventDefault();
var loc = window.location.href;
loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "Home" : loc;
console.log(loc + "/Insert");
$.ajax({
type: "GET",
url: loc+ "/Insert",
success: function (msg) {
console.log(msg);
//$('FrameforPopUp.html').html(msg);
//$("#ShowNextView").css(
$("#ShowNextView").html(msg);
//$("ShowNextView").src
showView(msg);
$("#ShowNextView").attr("disabled", "enabled");
//if (msg.d)
// showView(msg.d);
//else
// alert("Data is invalid")
},
error: function () {
alert("An unexpected error has occurred during processing.");
}
});
});
function showView(resultView) {
$("#ShowNextView").dialog({ //resultView
modal: true,
width: "auto",
height: "auto",
position: "center",
resizable: false,
closeOnEscape: true,
open: function (ev, ui) {
}
});
}
我的框架如下:
<iframe id="ShowNextView" style="visibility:hidden;">
但它不会显示带有弹出窗口的iframe。。
我希望iframe加载“插入”视图,并在btnInsert单击时调用ajax后在弹出窗口中显示它。请提供帮助?这是将HTML内容写入iframe的方法
$("#btnInsert").click(function (e) {
// ...
$.ajax({
type: "GET",
url: loc + "/Insert",
success: function (msg) {
showView(msg);
},
error: function () {
alert("An unexpected error has occurred during processing.");
}
});
});
function showView(resultView) {
$('<div>').append('<iframe id="ShowNextView"></iframe>').dialog({
modal: true,
width: "auto",
height: "auto",
position: "center",
resizable: false,
closeOnEscape: true,
open: function (ev, ui) {
$(this).find('#ShowNextView').contents().find('body').html(resultView);
}
});
}
$(“#btn插入”)。单击(函数(e){
// ...
$.ajax({
键入:“获取”,
url:loc+“/插入”,
成功:功能(msg){
showView(msg);
},
错误:函数(){
警报(“处理过程中发生意外错误”);
}
});
});
函数显示视图(结果视图){
$('').append('').dialog({
莫代尔:是的,
宽度:“自动”,
高度:“自动”,
位置:“中心”,
可调整大小:false,
closeOnEscape:没错,
打开:功能(ev、ui){
$(this.find('#ShowNextView').contents().find('body').html(resultView);
}
});
}
并从HTML中删除
演示:是弹出窗口本身不工作还是弹出窗口中没有html?嗯,我猜即使是iframe也没有正确加载。再加上根本没有弹出窗口不工作。。iframe还没有显示任何内容。它可以在演示中工作,对吗?因此,这意味着您可能没有正确加载数据。将
警报(resultView)
放在showView
中,它是否显示加载的内容?如果它在警报框中显示了部分视图的所有内容,请检查它是否在$中查找iframe(此)。查找('#ShowNextView').contents().find('body')
。我没有理解你。。如何找到答案?