admin管理员组文章数量:1332383
I am trying to return a record from a custom table. On the client side, I am sending an AJAX request.
<script>
var eventId;
var xmlhttp;
var xmlhttp = new XMLHttpRequest;
function doclick(ddl){
$evtid=-1;
$evtid =ddl.options[ddl.selectedIndex].value;
document.getElementById('hideme').value =
ddl.options[ddl.selectedIndex].value;
document.getElementById('ename').value =
ddl.options[ddl.selectedIndex].text;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = callback;
xmlhttp.open("POST", "/id.php", true);
xmlhttp.send();
}
function callback(){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('DESCRIPTION').innerHTML = xmlhttp.responseText;
}
}
</script>
$evtid is getting the correct data.
The id.php file:
<?php
$wpdb;
$sql='';
$eid;
$result;
echo print_r($result);
echo 'Howdy: '. print_r($eid);
try {
$sql='select description from mo_events where id = '. '11';
$result = $wpdb.get_results($sql);
echo "Im'''trying...";
} catch (Exception $exc) {
echo $exc->getTraceAsString();
echo 'Caught me.';
} finally {
echo "finally...out: ". print_r($result);
}
echo 'all the way... : '.print_r($result);
This is what shows on the Description textarea: "1Howdy: 1finally...out: 1}
So it looks like I have the client side working. Can someone help me figure out how to get the data back to the client? Thanks...Dan';
I am trying to return a record from a custom table. On the client side, I am sending an AJAX request.
<script>
var eventId;
var xmlhttp;
var xmlhttp = new XMLHttpRequest;
function doclick(ddl){
$evtid=-1;
$evtid =ddl.options[ddl.selectedIndex].value;
document.getElementById('hideme').value =
ddl.options[ddl.selectedIndex].value;
document.getElementById('ename').value =
ddl.options[ddl.selectedIndex].text;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = callback;
xmlhttp.open("POST", "http://www.memoriesof.website/id.php", true);
xmlhttp.send();
}
function callback(){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('DESCRIPTION').innerHTML = xmlhttp.responseText;
}
}
</script>
$evtid is getting the correct data.
The id.php file:
<?php
$wpdb;
$sql='';
$eid;
$result;
echo print_r($result);
echo 'Howdy: '. print_r($eid);
try {
$sql='select description from mo_events where id = '. '11';
$result = $wpdb.get_results($sql);
echo "Im'''trying...";
} catch (Exception $exc) {
echo $exc->getTraceAsString();
echo 'Caught me.';
} finally {
echo "finally...out: ". print_r($result);
}
echo 'all the way... : '.print_r($result);
This is what shows on the Description textarea: "1Howdy: 1finally...out: 1}
So it looks like I have the client side working. Can someone help me figure out how to get the data back to the client? Thanks...Dan';
Share Improve this question asked Jul 3, 2020 at 19:36 GreatDayDanGreatDayDan 153 bronze badges1 Answer
Reset to default 0- Your code (both client-side and server-side) makes no sense and is very ugly.
- You're not loading WordPress in your custom PHP script, so there's no way
$wpdb
would work. - To call a method of an object, you should do
$wpdb->get_results('... sql ...')
.
You shouldn't call PHP scripts directly anyway. It's better to create a REST endpoint or a rewrite endpoint inside your theme or plugin.
本文标签: How to return a record from a custom table by sending an AJAX request
版权声明:本文标题:How to return a record from a custom table by sending an AJAX request 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742293795a2448316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论