jquery - Issues with ajaxSubmit and serialize -
i'm having issues posting textarea contents database using ajax. i've tried use both jquery.form.js plugin malsap, ole fashon ajax, , cannot either post values out textareas. heres code:
html:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src="javascript/jquery.form.js"></script> <form id="defaultemail-ebook-form"> <label for="defaultemail-ebook">email ebook:</label><br> <textarea id="defaultemail-ebook" name="defaultemail-ebook"></textarea> <br> <div id="defaultemail-ebook-submit-div"> <input type="button" id="defaultemail-ebook-submit" value="set email"> </div> </form>
defaultemails.php
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $defaultemailebook = $_request['defaultemail-ebook']; if (isset($_get['defaultemail-ebook'])) { mysql_query("update default_emails set email_ebook='". $defaultemailebook ."' id = '1'"); echo $defaultemailebook; } $defaultemailnoebook = $_request['defaultemail-no-ebook']; if (isset($_get['defaultemail-no-ebook'])) { mysql_query("update default_emails set email_no_ebook='". $defaultemailnoebook ."' id = '1'"); echo $defaultemailnoebook; } ?>
ajax:
$(function() { $("#defaultemail-ebook-submit").click(function(){ var data = $('#defaultemail-ebook-form').serialize(); $.ajax({ url: "defaultemails.php", type: "post", data: data, success: function() { alert("yay"); } }); }); });
using .ajaxsubmit
$(function() { $( "#defaultemail-no-ebook-submit" ).click(function() { $("#defaultemail-no-ebook-form").ajaxsubmit({url: 'defaultemails.php', type: 'post'}).delay(100, function() { $("#current-no-ebook-message").text($("#defaultemail-no-ebook").val()); alert("email without ebook had been set!"); }); }); });
defaultemails.php update existing field text when accessed trailing name after (defaultemails.php?defaultemail-ebook=here+is+your+ebook), don't think php file. seems reason value of defaultemail-ebook isn't being submitted when use ajax call. appreciated!
your ajax call using post. in php file checking if $_get['defaultemail-ebook']
set. change $_post['defaultemail-ebook']
.
Comments
Post a Comment