I am using ASP.net MVC and the following is HTML
$.ajax({
type: "POST",
url: urlAjax,
dataType: 'json',
data: dataValue,
async: false,
beforeSend: function () {
$("#waitscreen").show();
},
complete: function () {
$("#waitscreen").hide();
},
success: function (data) {
alert("success")
},
error: function (jqXHR, textStatus, error) {
alert("fail")
}
});
<div id=waitscreen>
//some code
</div>
Code in external js
function _post(someparameter)
{
$.ajax({
type: "POST",
url: urlAjax,
dataType: 'json',
data: dataValue,
async: false,
beforeSend: function () {
$("#waitscreen").show();
},
complete: function () {
$("#waitscreen").hide();
},
success: function (data) {
alert("success")
},
error: function (jqXHR, textStatus, error) {
alert("fail")
}
});
}
Also tried adding a document ready to code above, it still doesn't work
The above code worked fine, and it showed and hid as expected, but now I need to repeat the ajax call on each page, so I decided to move to an external JS file, now the same code does not show waitscreen.
Things I tried:
- Loaded external script in head - Doesn't work
- Loaded external script at the end of the page - Doesn't work
Question: I want to do a job to hide and show from an external JS file