javascript - Wordpress and Ajax -
i've have created custom table in mysql. i've entered bit of test data see if can pull results. query successful when ran in template, know works. have tried convert ajax request seems no data being passed. i'm not sure missing, or possibly error have entered somewhere, seems when try turn ajax request nothing happens.
any ideas?
php
$q = intval($_get['q']); $pull = $wpdb->get_results( " select id, department, contact, forms referrals id = '$q' " ); foreach ( $pull $requestdata) { echo $requestdata->department; echo '<br />'; echo $requestdata->contact; echo '<br />'; echo $requestdata->forms; }
ajax
<script> function displaydata(str) { if (str=="") { document.getelementbyid("txt").innerhtml=""; return; } if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("txt").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","<?php echo content_url(); ?>/themes/child/get-referral.php?q="+str, true); xmlhttp.send(); } </script>
html
<select name="users" onchange="displaydata(this.value)"> <option value="">select person:</option> <option value="1">test 1</option> <option value="2"test 2</option> </select> <br> <div id="txt"></div>
you need change ajax request wp-admin/admin.ajax.php.
if open file find there constant setting named doing_ajax
. requests link can avoid normal header being sent browser because of setting doing_ajax
ture.
actually can debug this: visit <?php echo content_url(); ?>/themes/child/get-referral.php?q=xx
, find there other info sent. thats why ajax doesnt work.
Comments
Post a Comment