我试图让jQuery的对话框中按下“给予好评”链接这里经过,弹出了:http://www.problemio.com无法获取jQuery的对话框弹出
(我是从这个例子正常工作,然后修改它因为它没有为我工作:http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/)
这里是jQuery代码我至今不工作:)
<script type="text/javascript">
$(document).ready(function()
{
var $dialog = $('.dialog')
.dialog({
autoOpen: false,
title: 'Basic Dialog'
});
$('.vote_up').click(function()
{
problem_id = $(this).attr("data-problem_id");
var dataString = 'problem_id='+ problem_id + '&vote=+';
$.ajax({
type: "POST",
url: "/problems/vote.php",
dataType: "json",
data: dataString,
success: function(data)
{
// ? :)
alert (data);
},
error : function(data)
{
//alert("ajax error, json: " + data.responseText);
errorMessage = data.responseText;
if (errorMessage == "not_logged_in")
{
alert ("errr");
// Try to create the popup that asks user to log in.
//$(this).dialog();
//$(".dialog").dialog();
$dialog.dialog('open');
// prevent the default action, e.g., following a link
return false;
}
else
{
alert ("not");
}
//alert(JSON.stringify(data));
}
});
//Return false to prevent page navigation
return false;
});
$('.vote_down').click(function()
{
alert("down");
problem_id = $(this).attr("data-problem_id");
var dataString = 'problem_id='+ problem_id + '&vote=-';
//Return false to prevent page navigation
return false;
});
});
</script>
上面这段代码,我还有一个jQuery的功能也有一个documentOnready检查。这很重要吗?我应该使对话框代码全球?如果是这样,我该怎么做?
在任何情况下,我怎样才能使用我现在的设置打开对话框?
谢谢!
改变了我的jQuery进口到这一点:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.16/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" />
你的代码看起来不错。警报(“errr”);警报是否显示? – BNL
首先检查并确保在初始化对话框'$ dialog.dialog('open');'后执行以下操作,弹出对话框。之后,您可以进一步诊断ajax响应是否是问题。 –
@BNL是,警报确实显示。我得到的错误是关于对话框对象。和其他人建议一些我添加到我的问题,这也给出了一些进口错误:) – GeekedOut