php - Passing html form value through json/ajax -
I have the basic HTML form and I use jquery and json to pass the value of the form in PHP form I am trying to I am new to this, but I did a lot and I thought I had entered everything right. The page can not be reloaded when I hit Submit (and the behavior that I want to), but I have coded a JavaScript alert to see if the data is being passed and that alert is not working is. I am looking for this code for hours and I can not find any error. Can anyone tell me why the alert is not working?
Here's my main one. Php
& lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Leader & lt; / Title & gt; & Lt; link rel = "stylesheet" type = "text / css" href = "main.css" & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div class = "container" & gt; & Lt; Form action = "post.php" method = "post" id = "add" & gt; & Lt; Input type = "text" class = "leader" name = "name" placeholder = "leader" & gt; & Lt; Input type = "submit" value = "send" /> & Lt; / Form & gt; & Lt; Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> & Lt; Script type = "text / javascript" src = "jquery-ui-1.10.4.custom.js" & gt; & Lt; / Script & gt; & Lt; script src = "globe.js" & gt; & Lt; / Script & gt; & Lt; ul id = "hour_jone" & gt; & Lt; Li class = "nine" & gt; 9 & lt; / li & gt; & Lt; Li class = "ten" & gt; 10 & lt; / li & gt; & Lt; li class = "eleven" & gt; 11 & lt; / li & gt; & Lt; Li class = "twelve" & gt; 12 & lt; / li & gt; & Lt; Li class = "one" & gt; 1 & lt; / li & gt; & Lt; Li class = "two" & gt; 2 & lt; / li & gt; & Lt; Li class = "three" & gt; 3 & lt; / li & gt; & Lt; Li class = "four" & gt; 4 & lt; / li & gt; & Lt; Li class = "five" & gt; 5 & lt; / li & gt; & Lt; li class = "six" & gt; 6 & lt; / li & gt; & Lt; Li class = "seven" & gt; 7 & lt; / li & gt; & Lt; Li class = "eight" & gt; 8 & lt; / li & gt; & Lt; Li class = "nine" & gt; 9 & lt; / li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt; Here's my globe. Js
$ ('# add'). ('Submit', function () {var name = $ ('.leader'). Val (); $ .ajax ({url: 'post.php', datatype: 'jason', type: 'post' , Data: name, success: function (data) {if (data. Success) {warning ('result' + data result);}}}) return false;}); My posts here. php
& lt; Php header ('content type: text / javascript'); $ Json = array ('success' = & gt; wrong, 'result' => gt; 0); If (isset ($ _ POST ['name'])) {$ name = $ _POST ['name']; $ Jsan ['success'] = true; $ Json ['Result'] = $ name; Echo json_encode ($ json); ? & Gt;
Make changes to globe.js and it works: < Pre => $ ('# add') ('submit', function () {var name = $ ('leader'). Val (); $ .ajax ({url: 'post.php' , Data type: 'jason', type: 'post', data: 'name =' + name, success: work (data) {if (data.success) {warning ('result is' + data result);} } }); return false; });
Comments
Post a Comment