Monday, 22 April 2013

Ajax method of calling Action method of a controller:

I need to call a action method in order to save the uploaded image file using Jquery or the Ajax method. So below is the code for it.


$.ajax({
           url:
"/Image/UploadTest", // Image is the controller & UploadTest is Action Method

           type: "POST",
           data: $("#frmTest"
).serialize(),   // Here provide the form Id
           async:
false,
           cache:
false,                      // Don't keep the cache
           beforeSend:
function () {  // This Executes before calling the Ajax Request
                  $(
"#uploadProgress").show();   // Here I am showing Uploader image
              },
           complete:
function () {
                  $(
"#uploadProgress").html("Upload completed"); 

                // Executes on Ajax request complete
              },
          success:
function (msg) {

                 
if (msg == "ok")
                      $(
"#uploadProgress").hide();  // hiding the uploader image on successs
                 
else
                      alert(
"Error while uploading");

              }
          });

No comments:

Post a Comment