2
Answers

Ajax related Question

Why everytime i need to empty the div if i want to add ajax resonse to my view. without this ajax respose not set to view here is my code.

      $.ajax({
            type: "POST",
            url: "/JS/UploadImage/",
            mimeType: "multipart/form-data",
            processData: false,
            contentType: false,

            data: formdata,


            success: function (result) {


                if (result !== null) {
                    let parsed = JSON.parse(result);
    

                 
                    if (parsed.data!== null) {
                        let substr = parsed.data.substring(14);
                        $("#rname").empty();
                        $("#rname").append(
                            '<p class="font-weight-bold">' + substr + '</p>'

                        )
                    

                    }
                    else {
                        alert("Error occured while uploading");
                    }
                }

            },

            error: function (result) {
                alert("uploading failed");
            }

        });

is there any alternate way to do this. i want exactly what my code is doing but with the different approach. its my dottnet mvc app

Answers (2)