michelleisconfused michelleisconfused - 6 months ago 23
jQuery Question

open jquery-ui dialog based on ajax response

I'm trying to open a jquery-ui dialog when the response of checklatestnews.php meets the condition rec != "0". I created a test checklatestnews.php file where the response is always "1", yet a jquery-ui dialog will still not open. Any help would be appreciated.

<div id="dialog">

<script type="text/javascript">

$("#dialog").dialog(
{
bgiframe: true,
autoOpen: false,
height: 100,
modal: true
}
);
</script>

<script type="text/javascript">

var check_latestnews;
function CheckForLatestNewsNow() {
var str="chklatestnews=true";
jQuery.ajax({
type: "POST",
url: "checklatestnews.php",
data: str,
cache: false,
success: function(res){
if(res != "0") {


$("#dialog").html(response).dialog("open");

}

}
});
}
check_latestnews = setInterval(CheckForLatestNewsNow, 5000);
</script>

Answer
$.post("checklatesnews.php", {action: "check"}, function(response) {
    .....
    $("#dialog").dialog("open");
});