1

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

2
  • 1
    Possible duplicate of Why are new lines not working in this javascript alert window? Commented May 3, 2017 at 9:28
  • return Content(mystring , "html"); should really be return Content(mystring , "text/plain"); Also the problem is with the server side, you're not sending down a new line you're sending down "\n" Commented May 3, 2017 at 9:29

1 Answer 1

1

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);
            }                
        }});
Sign up to request clarification or add additional context in comments.

1 Comment

@tripathy try this hope it helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.