javascript - PHP JSON Post string from Textbox (Searchbox) and return result in textbox as string -
i trying create simple webpage goggle, user type there search e.g "what england?" , json post string searchbox specified url (for e.g. goggle search api) username , password authentication , return result given url webpage answer.
i need simple idea of sample code. new in php
you can using ajax, can in jquery easy search jquery docs, can in many other ways pure js...
edit:
here simple example ,
<html> <head> <title>search example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="./content.js"></script> </head> <body> <input type="text" id="searchinput" /> <input type="submit" id="searchsubmit" value="click search" /> </body> </html>
and jquery code (content.js):
$(document).ready( function() { $('#searchsubmit').on('click', function(){ var text_to_search = $('#searchinput').val(); //get searchbox text send using ajax $.ajax ({ data: ({ text: text_to_search }), //these get, post variables want send backend //(in case sending text post variable) method: "post", url: "./backend.json", //the url want send request to.. success: function(result) { // (result) variable data backend sent alert(result); }, error: function() { //failed alert("couldnt contact backend.."); } }); }); })
in example above on ajax succes jquery alert text backend gave back...
Comments
Post a Comment