我有以下设置,它的php部分应该运行,我已经测试并确认,这让我相信问题是
1)在我的JavaScrip编码中 2)在我的设置中
这是我调用的php文件
<?php
$option = array();
$option['driver'] = 'mssql';
$option['host'] = 'host';
$option['user'] = 'user';
$option['password'] = 'password';
$option['database'] = 'database';
$option['prefix'] = '';
$db = JDatabase::getInstance( $option );
$result = $db->getQuery(true);
$result->select($db->quoteName(array('trackandfieldresults')));
$result->from($db->quoteName('[TrackData]'));
$db->setQuery($result);
$row = $db->loadRowList();
print_r($row);
?>
这是我的语法并试图通过JavaScript调用来获取数据
<form id="form1" method="post">
<div style="padding-top: 10px;"><input type="submit" value="Submit" id="ajaxButton" /></div>
<div style="padding-top: 10px;"> </div>
</div>
<script type="text/javascript">
(function() {
var httpRequest;
document.getElementById("ajaxButton").onclick = function() { makeRequest('Test.php'); };
function makeRequest(url) {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = alertContents;
httpRequest.open('GET', url);
httpRequest.send();
}
function alertContents() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
alert(httpRequest.responseText);
} else {
alert('There was a problem with the request.');
}
}
}
})();
</script>
</form>
在上面的语法中应该改变什么,以便将结果从我的php文件返回到我的JavaScript函数?
每次尝试执行时,我都会收到警告There was a problem with the request
修改
开发工具显示了
500内部服务器错误
为了确保问题不在于使用print_r
结束php文件,我将文件更改为这样读取,以便我可以确认结果是echo
$var = print_r($row, true);
echo $var
答案 0 :(得分:0)
你的桌子真的叫做[TrackData]吗?还是TrackData?