I am implementing Ajax using jQuery. In my code I have tried to change the content of a <p>
element with id #newpara
in the .fail{}
function.
.fail(function (jqXHR, textStatus) {
('#newpara').text("Request Failed"); alert("fail");
}
Also I have tried to change the content of <p>
with id #newpara
in the complete section
complete: function () {
alert("Request complete");
$('#newpara').text("Request complete.");
In HTML <body>
I have
<p id="newpara">Old Text</p>
But I find that the the content of paragraph tag is changed temporarily when the execution point hits these functions. (I get to know this because the text in the paragraph changes from 'Old Text' to 'Request Complete' when I see the alert.) Once the request is complete the content of paragraph is back to its original state which is 'Old Text'.
Complete ajax code for reference:
$.ajax({
url: "Home/Action1",
type: "post",
success:function(results){
alert(results+" :: status");
},
dataType: "json",
contentType:"application/json; charset=utf-8",
data: JSON.stringify({
Title: $('#Title').val(),
Content: $('#Content').val()
}),
complete: function () { alert("Article Saved"); $('#newpara').text("Hello this is new one"); alert('breakpoint'); },
beforeSend: function (xhr) {
xhr.overrideMimeType("text/plain; charset=x-user-defined");
}
})
.done(function (data) {
if (console && console.log) {
console.log("Sample of data::", data.slice(0, 100));
}
alert("Saved!");
}
)
.fail(function (jqXHR, textStatus) {
$('#newpara').text("Hello this is after failed");
alert("Request failed:: " + textStatus);
});
}