Ok I'm loading a form into a page via an ajax call like so:
$('.ajax_click').on('click', function(event) {
event.preventDefault();
/* Act on the event */
var getmsgtoload = $(this).find('.ajax_get_msg').attr('href');
var getpelytoload = $(this).find('.ajax_get_reply').attr('href');
//get reply
$.ajax({
url: getpelytoload,
}).done(function(data) {
var getreply = $(data).find('#reply_div').html();
$('#reply_div').replaceWith('<div id="reply_div">'+getreply+'</div>');
//Process our send!
$('#create').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
})
.done(function(data){ // the file to call
console.log(data);
$('#created').html('<h1>Success</h1>'); // update the DIV
})
.fail(function(){
console.log('error on the from....');
});
return false; // cancel original event to prevent form submitting
});
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
I'm trying to then send the data from the form via ajax aswell, but the data argument just returns the whole page instead of just the form. why? Chris Clarification The form will not "POST" data At all but it does work on the page I'm pulling the form in from it goes like so: I'm calling in a form into DIV A with an ajax call from page A into Page B in the ajax's Callback success fucntion I'm then running the ajax to send the form data via serialize but it will not send when the form is viewed on the page A it works fine but not when it's pulled into page B! Chris