php - Use jquery framwork for ajax -
first let me describe situation :
i create form each field have button. if click on bring data database , show in div. example
<div class="main"> <div class="form"> <!-- form code here--> </div> <div class="help"> <!-- div show data using ajax. need make database query using id of show data here--> </div> </div><!--end of main-->
now read ajax in w3 schools found solution there. :
<script> function loadxmldoc(a) { var xmlhttp; var temp = "myname.php?id=" + a; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get",temp,true); xmlhttp.send(); } </script> <h2>ajax</h2> <button type="button" onclick="loadxmldoc('1')">request 1</button> <button type="button" onclick="loadxmldoc('2')">request 2</button> <button type="button" onclick="loadxmldoc('3')">request 3</button> <div id="mydiv"></div>
if click on button , send id parameter works. after making google search found better use jquery framework ajax. didn't beginner tutorials in google this.
now if above code ok use in case give me link or how make database query on javascript , values , set div using ajax.
if not way use ajax please give me instruction how can use ajax getting values database , show in particular div. please keep in mind need send id on function whom make database query.
i using wordpress framework.
include jquery.js in page simple as
function loadxmldoc(a) { $('#mydiv').load("myname.php?id=" + a); }
if want complete jquery solution, recommend using jquery event registration like
html
<button type="button" class="requester" data-request="1">request 1</button> <button type="button" class="requester" data-request="2">request 2</button> <button type="button" class="requester" data-request="3"request 3</button> <div id="mydiv"></div>
js
$(function() { $('.requester').click(function() { $('#mydiv').load("myname.php?id=" + $(this).data('request')); }); });
Comments
Post a Comment