javascript - Trying to serialize form with ajax and jquery -


i'm trying form submit user input modal in jquery via ajax ajax call isn't picking user input. ajax call being made server when check if user input has registered server it's blank.

html:  <body>   <div id="home">     <p>home</p>   </div>   <div id="welcome">     <span>welcome  <?php echo $_session['user']; ?></span>   </div>   <form id="form">     <p1>please enter in hotkey below</p1>     <input type="text" id="hotkey" placeholder="hotkey">     <input id="submit" type="button" value="submit">   </form>   <div id="keyshortcut">     <input type="text" id="keyshortcut" placeholder="hotkey">   </div>   <div id="select_button">     <button id="select-hotkey">select hotkey</button>   </div>   <div id="hotkeyselection">     <span>this hotkey have selected:</span>   </div>   <div id="logout">     <a href="logout.php?logout">log-out</a>   </div>   <br> </body> 

jquery:

$(function() {    dialog = $("#form").dialog({      autoopen: false,      height: 250,      width: 350,      modal: true,      buttons: {        cancel: function() {          dialog.dialog("close");        }      },      close: function() {        form[0].reset();      } });  $("#select-hotkey").button().on("click", function() {   dialog.dialog("open"); }); 

ajax:

$(document).ready(function() {   $("#submit").click(function() {     var hotkey = $("#hotkey").val();     var datastring = 'hotkey=' + hotkey;     alert(datastring);     $.ajax({       type: "post",       url: "submithotkey.php",       data: $("#form").serialize(),       success: function(result) {         alert(result);       }     });   }); }); 

php

<?php $con=''; $con= mysqli_connect("localhost","***","****","***"); $curr_user=$_session['user']; $data=$_post['serialize']; $hotkey=$data['hotkey']; $query = "insert users(hotkey) values ('$hotkey',) username='$curr_user'"; $run_query = mysqli_query($con, $query); ?> 

you need give form fields name= value

$().serialize(); 

will create string of params name

example: http://jsbin.com/sowutafuju/edit?html,js,console,output


Comments

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -