I want the result of this Ajax request to fill the JavaScript hintArray
. That is, I want hintArray
to contain the same values as $row
. Can this be done in a simple way?
How should the php file output be made?
Is hintArray = JSON.parse(this);
correct?
Many thanks
JavaScript
var hintArray = new Array();
postAjaxRequestFunktion(minFunktion, 'getHint.php', 'id =1')
function minFunktion()
{
hintArray = JSON.parse(this);
}
function postAjaxRequestFunktion(minFunk,minUrl, mittArg)
{
var contenttype = 'application/x-www-form-urlencoded'
var minRequest = new skapaAjaxObjekt(minFunk)
if (!minRequest) return false
minRequest.open('POST', minUrl, true)
minRequest.setRequestHeader('Content-type', contenttype)
minRequest.setRequestHeader('Content-length', mittArg.length)
minRequest.setRequestHeader('Connection', 'close')
minRequest.send(mittArg)
return true
}
function skapaAjaxObjekt(minFunk)
{
try { var minRequest = new XMLHttpRequest() }
catch(e1) { try { minRequest = new ActiveXObject("Msxml2.XMLHTTP") }
catch(e2) { try { minRequest = new ActiveXObject("Microsoft.XMLHTTP") }
catch(e3) { minRequest = false }}}
if (minRequest) minRequest.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200 &&
this.responseText != null)
minFunk.call(this.responseText)
}
return minRequest
}
getHint.php
$result = mysql_query("SELECT hint01,hint02 FROM main WHERE id = '00000001'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);