In my jQuery dialog, since wanted to refresh the page when OK
button is clicked, I added a location.reload()
inside success function.
Now, when user clicks on Cancel
button and tries to open the dialog again, it doesn’t open. I can add another location.reload()
inside the following function like this:
text: "Cancel",
click: function() {
$(this).dialog("close");
location.reload();
}
But I am wondering if there is anything better than using location.reload() and without refreshing the page?
<div id="add_dialog" title="Add New Data" style="display:none;">
<form>
<p>
<b>Name:</b><br/>
<input id="dataName" type="text" name="name" />
</p>
<p>Description:
<textarea id="dataDescription" name="dataDescription" rows="4" cols="20"></textarea>
</p>
</form>
</div>
$("#add_dialog").dialog({
autoOpen: false,
closeText:false,
buttons: [
{
text: "Ok",
icon: "ui-icon-heart",
click: function() {
console.log("OK button clicked");
let jsonData = {some json data }
$.ajax({
type: "Post",
url: "url",
data: JSON.stringify(jsonData),
contentType: 'application/json',
async: true,
cache: false,
success: function(data) {
$.ajax({
url:'url1',
type:"POST",
data:'url2',
contentType:"text/uri-list",
dataType:"json",
success: function(){
location.reload();
}
})
}
});
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}
}
]
});