kilkadg
kilkadg

Reputation: 2317

Adding a line break to an alert() using Ajax

I have found this link where shows me that \n works for my goal.

But it is not working in the way I am doing it.

$.ajax({
        url:'ajax/core/Ajax_Request.php',
        type:'POST',
        dataType:'json',
        success:function (result) {
            alert(result.error);
            }
});

In the php file I have

$resultado['error']='1\n2\\n3.';
echo json_encode($resultado);

And it is not showing a break line neither with \n or \\n

It is showing 1\n2\n3

Thanks for your time.

Upvotes: 1

Views: 2524

Answers (1)

Saic Siquot
Saic Siquot

Reputation: 6513

you need doble quotes on php side:

$resultado['error']= "1\n2\n3";
echo json_encode($resultado);

Upvotes: 2

Related Questions