Ok so here is the scenario : The app is built with Ajax requesting How many services do we need ? ( I don't validate anything for this purpose but I should )
Say we give five as an input the form return with 5 boxes and a submit button
<script>
function test(){
var num = $('#numServ').val();
var form = "";
form += "<form name='form2' id='services' method='POST' action='<?php echo $_SERVER['PHP_SELF'];?>'>";
for(m=0;m<num;m++){
// alert("<br>Voice le param"+m);
form += "<br><input type='text' name='services"+m+"' value=''>";
}
form += "<input type='submit' name='services' id='btnServices' value='SERVICES'>";
form += "</form>";
alert(form);
$('#generated').append(form)
}
</script>
This part works ... but when I try to submit the form usin Ajax which the function for this Ajax call was place in the document.ready function it jst doesn't work.
$('#form2').submit(function(){
alert("Form Submitted");
/*
THE WHOLE CODE COMMENTED OUT IT STILL WON'T WORK
var result = $(this).serialize();
alert(result);
$.ajax({
url:"./content.php",
data: result,
type: "POST",
// cache:false,
dataType:"html",
success: function(data,jqXHR){$('body').append(data);},
error: function(){alert('Check Ajax request');},
complete:function(){alert("Ajax complete");}
});
*/
return false;
});
I have been at it for days now. Any other forms that are not built using jquery will work using this method as the form is already loaded on the page and not beeing made by ajax on the fly.
I believe my issue lies with Ajax making the form after the page has been loaded ... even though my Ajax call to sumit the form is in the head inside the document.ready function.
Any ideas ?