[英]Open Jquery dialog from inside Ajax request?
I have a problem with my current javascript/ajax request. 我当前的javascript / ajax请求有问题。 I'm trying to open a Jquery dialog from inside my
.append
my code follows: 我试图从我的
.append
内部打开一个Jquery对话框,代码如下:
for (var i in rows)
{
var row = rows[i];
var id = row[0];
var NewEdit = row[0];
var PreviousEdit = row[1];
var FunctionName = row[2];
var FunctionID = row[2]
function ShowInfo()
{
dialog('Original: <br>'+PreviousEdit+'<br><br> New: <br>' +NewEdit);
}
$('#RecentEdits').append("<br>Page: <a href=Page.php?ID="+FunctionID+">"+FunctionName+"</a> - <a href='#' OnClick='ShowInfo()'>Info</a>");
}
I have only pasted relivant code, if required I can post the entire function. 我只粘贴了相关代码,如果需要,我可以发布整个函数。
I know for a fact, my variables are correctly set due to them being printed out. 我知道,由于变量已被打印出来,因此变量设置正确。
How can I open up a Dialog box showing more information from inside a Javascript function? 如何打开一个对话框,显示来自Javascript函数内部的更多信息?
Solution: 解:
As there is no correct replies. 由于没有正确的答复。 I have used OQJF's example and produced this:
我使用了OQJF的示例并生成了此示例:
<script>
function ShowInfo(a,b)
{
alert('Original: \n'+unescape(a)+'\n\n New: \n'+unescape(b));
};
</script>
<script>
//window.setInterval(function()
//{
$(function ()
{
$.ajax({
url: 'RecentUpdates.php', data: "", dataType: 'json', success: function(rows)
{
$('#RecentEdits').empty();
for (var i in rows)
{
var row = rows[i];
var id = row[0];
var NewEdit = row[0];
var PreviousEdit = row[1];
var FunctionName = row[2];
var FunctionID = row[3];
$('#RecentEdits')
.append("<br>Page: <a href='Page.php?ID="+FunctionID+"'>"+FunctionName+"</a> - ");
$('#RecentEdits').append("<input type='button' onClick=ShowInfo('"+escape(PreviousEdit)+"','"+escape(NewEdit)+"'); value='Show'>");
}
}
});
});
// }, 1000);
</script>
which has enabled me to access the function from my Javascript printout. 这使我能够从Javascript打印输出访问该功能。
I had troubles with the quotes wrapped around my html so i have decided to make two appends. 我在用html括起引号时遇到了麻烦,因此我决定进行两个附加。 And this seems to work just fine!
而且这似乎很好!
While firstly I think you should set the function showInfo outside of the loop and set 2 parameter for it. 首先,我认为您应该在循环外设置showInfo函数,并为其设置2参数。 Below is the sample code that I didn't test but It should be almost like this.
下面是我没有测试过的示例代码,但是应该几乎像这样。
function ShowInfo(orginVal,newVal)
{
var msg =('Original: <br>'+orginVal+'<br><br> New: <br>' +newVal);
$(<div>msg</div>).appendTo('body).dialog();//maybe you can add some options for dialog
}
below part seems be in another function. 下面的部分似乎在另一个功能中。
for (var i in rows)
{
var row = rows[i];
var id = row[0];
var NewEdit = row[0];
var PreviousEdit = row[1];
var FunctionName = row[2];
var FunctionID = row[2]
$('#RecentEdits').append("<br>Page: <a href=Page.php?ID="+FunctionID+">"+FunctionName+"</a> - <a href='#' OnClick='ShowInfo(/*add your 2 parameters here*/)'>Info</a>");
} s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.