I am new to JSON format, so please forgive my ignorance. But for some reason I need to add some line breaks to my json_encode array so that it parses multiple lines. I searched and searched, but nothing matched my situation.
It is displayed as:
Following formats accepted: www.website.com website.com website.net/something
But I am looking for the output as follows:
Website needs to be in the following formats: www.website.com website.com website.net/something
I tried:
echo json_encode( array( 'status' => 'failed', 'message' => "Website needs to be in the following formats:\n www.website.com\n website.com\n website.net/something" ), JSON_PRETTY_PRINT);
But Javascript parses it as a literal string, so newline characters are ignored and output. Can I send data from PHP to javascript using the direct JSON format or do I need to use an array?
I also tried using <br /> .
EDIT:
I am outputting the following path:
$.ajax({ url: "/forms/content_process.php", type:'POST', data: $(".content_cat").serialize(), processData: false, dataType: "json", success: function(response) { if (response.status == "failed") { $(".content_status").css( "background-color", "red" ); $(".content_status").text(response.message).slideDown("normal"); } else { $(".content_status").css( "background-color", "green" ); $(".content_status").text("Your category was submitted!").slideDown("normal"); } } });
source share