bonaca Posted September 30, 2013 Share Posted September 30, 2013 contact.php ... html form ... $('#submit').click(function(){ $.post("mail.php", $("#contact").serialize(), function(response) { $('#success').html(response); }); return false; }); mail.php is a separate file (for sending mail), and everything works in this arrangement. But I need to load contact.php into index.php $('#divR').load('chapters/contact.php'); so corresponding js line becomes $.post("chapters/mail.php", $("#contact").serialize(), function(response) {... Submitting the form in this case response from mail.php is received, but POST array is empty, i.e. form doesn't send any data to mail.php !? Quote Link to comment https://forums.phpfreaks.com/topic/282552-form-doesnt-send-any-data-if-form-file-is-loaded-into-indexphp/ Share on other sites More sharing options...
Ch0cu3r Posted September 30, 2013 Share Posted September 30, 2013 Can not use php to include contact.php? <?php include 'chapters/contact.php'; ?> Using PHP include will return the raw php source code of contact.php. The PHP code in contact.php will be parsed at the same time as index.php. If you use jquery $.load() function it'll only return the html source code of contact.php (the output). Quote Link to comment https://forums.phpfreaks.com/topic/282552-form-doesnt-send-any-data-if-form-file-is-loaded-into-indexphp/#findComment-1451819 Share on other sites More sharing options...
bonaca Posted September 30, 2013 Author Share Posted September 30, 2013 Can not use php to include contact.php? Yes, i can, but in that case I must rearange the entire site. Is there any solution with $.load(), please ? Quote Link to comment https://forums.phpfreaks.com/topic/282552-form-doesnt-send-any-data-if-form-file-is-loaded-into-indexphp/#findComment-1451823 Share on other sites More sharing options...
Solution Ch0cu3r Posted September 30, 2013 Solution Share Posted September 30, 2013 Does contact.php contain PHP code? .load() will only return the output from this script, no PHP source code is returned. For example if contact.php had in it $myVar = 'abc'; And then in index.php you had echo $myVar; the variable $myVar will be undefined. PHP code will not be passed back to index.php If contact.php contains no PHP code then you are fine to use .load. Quote Link to comment https://forums.phpfreaks.com/topic/282552-form-doesnt-send-any-data-if-form-file-is-loaded-into-indexphp/#findComment-1451840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.