Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requesting a form via $.ajax returns only form elements

Tags:

jquery

ajax

forms

I'm using AJAX to fetch a form dynamically into another page for security reasons. The Ajax works fine but the result is displaying form elements only not the form tag

$.ajax('form.php?username='+username).done(function (data) {
     alert(data);
     $("#test").html(data);
})

The alert displays the whole form including the form tag with the related attributes but the form does not submit because the form tag has been removed and while checking the code through firebug that's what I found

enter image description here

and this the result of alert(data)

enter image description here

I've tried this but it didn't insert the form tag at all

$("#test").html(data).promise().done(function(){
    $("#test").html.wrap('<form action="page.php">');
});
like image 643
PHP User Avatar asked Feb 17 '26 08:02

PHP User


1 Answers

A FORM cannot contains any other FORM, see Spec

form must not contain other form elements.

Browser engine strips out any nested FORM tags.

like image 195
A. Wolff Avatar answered Feb 19 '26 21:02

A. Wolff