-1

I have the problem.

I send ajax request as dateType: json, and get HTML code, paste it as $(selector).html(res.html), and browser don't understand attr required="required" and type="email", does not works.

Only if I change dateType on HTML it works.

How can I make it work?

$.ajax({
  dataType: "json",
  success: function (res) {
    $("#html").html(res.html);
  }
})

res:

{"status": true, "html": "<form id=\"ajax-form\"><input type=\"email\" name=\"email\" required=\"required\" /></form>"}

http://jsfiddle.net/6a2Ja/2/

PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
Swain
  • 75
  • 6

1 Answers1

0

Your HTML works fine. The <input> has all the attributes on it that it should. The problem is that your submit button is in the wrong spot. It needs to be inside the form.

Do that, then it works fine. So, basically make your JSON:

{"status": true, "html": "<form id=\"ajax-form\"><input type=\"email\" name=\"email\" required=\"required\" /><input type=\"submit\" value=\"send\" /></form>"}

DEMO: http://jsfiddle.net/6a2Ja/3/

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • Yeah nice, thanks you. but that if i do not have buttons "submit" in form? example: [http://jsfiddle.net/6a2Ja/4/](http://jsfiddle.net/6a2Ja/4/) – Swain Dec 04 '13 at 22:23
  • @Swain: If the submit button isn't in the form, then it won't know to act on that form. You'd then need to use JavaScript to have the button submit the form. – gen_Eric Dec 05 '13 at 14:46
  • Thank u very much for answer. rewrite my code, now works fine. – Swain Dec 05 '13 at 18:29