I have written a function which basically takes some input as text and set of files. And using Generic handler i save the files and text all works fine. The issue is after the process i want to some some alert or success message how can i achieve that?
JS:
var appID = $("#hidden_applicationID").val();
var messageText = escape($("#screeningFeedback").val());
var files = $("#fileScreening").get(0).files;
var fileData = new FormData();
for (var i = 0; i < files.length; i++) {
fileData.append("fileInput", files[i]);
}
fileData.append("uniqueapplicationID", appID);
fileData.append("messageText", messageText);
$.ajax({
url: "ScreeningUpload.ashx",
data: fileData, type: "POST",
processData: false,
contentType: false,
cache: false,
dataType: "json",
success: function (mydata) {
alert("hello");
//$("#screeningFeedback").val();
//showtoaster("Thank you for your submission!");
}
});
C#
public void ProcessRequest(HttpContext context)
{ // DOING SOMETHING
context.Response.Clear();
context.Response.Write("<script type='text/javascript'>alert('Hello, world');</script>");
}
How can i achieve the above tried many things but no luck.
Thank you
If you are sending JavaScrip as response from backend then add that response in DOM. Browser will execute it.
$.ajax({
url: "ScreeningUpload.ashx",
data: fileData, type: "POST",
processData: false,
contentType: false,
cache: false,
dataType: "json",
success: function (mydata) {
$(document.body).append(mydata);
},
error: function(jqXHR, textStatus, errorThrown){
alert("Status:"+textStatus+"\nError:"+errorThrown);
}
});