简体   繁体   中英

Prevent redirect and return the json result in a div MVC/C#/Jquery

This is my function below, I would like some help to figure out how can i prevent redirect after this function has been called and return my json result in the same page in a div called "resultMessage".

function PdfHeaderAndFooterManager() {
 $('#formPdfImages').submit(function(event) {
         $.post("@(Url.Action("PdfHeaderAndFooterManager", "Dashboard"))", $(this).serialize(), function(data) {
            if (data.success) {
                $("#resultMessage").text(data.message);
            } else {
                $("resultMessage").text(data.message);
            }

        });
    });
}

thanks.

$('#formPdfImages').submit(function(event) {
         //event.preventDefault(); // prevent the page reload
         $.post("@(Url.Action("PdfHeaderAndFooterManager", "Dashboard"))", $(this).serialize(), function(data) {
            if (data.success) {
                $("#resultMessage").text(data.message);
            } else {
                $("resultMessage").text(data.message);
            }
           return false;
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM