tripathy
tripathy

Reputation: 385

How to render html in ajax alert on success using asp.net mvc and jquery

I have action result which sends content like below

 public ActionResult MyAction()
    {
       string mystring = //doing some thing

       return Content(mystring , "html");
    }

client side

 $.ajax({
            url: "/MyController/MyAction",
            type: "POST",
            dataType: "html",
            data: details,
            success: function (response) {
                if (response != "") {
                    alert(response);
                }                

            }
        });

now My string or response from action what i am sending is (it can be more numbers like 1 , 2 ,3 dynamic )

"\\n 1: blah blah.\\n 2: blah blah"

and in the alert its coming as

  \n 1: blah blah.\n 2: blah blah

how to make the alert look like

1.blah blah.
2.blah blah.

Cant change anything in server side , change allowed only in client side

Upvotes: 1

Views: 513

Answers (1)

Zaheer Ul Hassan
Zaheer Ul Hassan

Reputation: 781

Update your client side code.

Replace the response.

 $.ajax({
         url: "/MyController/MyAction",
         type: "POST",
         dataType: "html",
         data: details,
         success: function (response) {
         if (response != "") {
            response = response.replace(/\\n/g, "\n");
            alert(response);
            }                
        }});

Upvotes: 1

Related Questions