jQuery Form Plugin - HTML inside JSON respone
I'm using Malsup's jQuery Form Plugin. I'm sending the form back to be validated and trying to return a JSON response similar to this:
{
"complete":0,
"formText":"<div class=\"error\">...<\/div>",
"returningNumber":12345
}
The json object is encoded using PHP's json_encode()
function. In the event that the form has errors in it (empty fields, invalid inputs) the formText
variable carries the entire html of the form开发者_C百科 to the front end and is then inserted in place of the current form.
The problem is that, from what I can tell, the Form Plugin does not allow HTML to be carried inside of a JSON object. I will only fire the success function when the data variable does not carry any HTML in it.
Is there any way around this? Am I not escaping something properly? Any info on this problem would be appreciated. Thanks in advance.
You could encode your HTML part using htmlentities()
PHP function, and then you can decode it like described in this question.
精彩评论