readyState
== 4){ ProcessXHR(xhr, responsediv, addcontent); } }
xhr.send('');
}
return returnvalue;
}
function ProcessXHR(xmlHttpReq, responsediv, addcontent){
var responseText = xmlHttpReq.responseText ? xmlHttpReq.
responseText : '';
if(addcontent){document.getElementById(responsediv).innerHTML
+= responseText;}
else {document.getElementById(responsediv).innerHTML =
responseText;}
}
function ShowDetails(url, responsearea, addcontent, returnvalue){
document.getElementById(responsearea).innerHTML = '
![]()
class="loadimg" src="'+loading.src+'" alt="loading..."
width="16" height="16" />';
return XHReq(url, responsearea, addcontent, returnvalue);
}
Mobile AJAX
[ 188 ]
7. The library now gives us functions that we can use to implement AJAX.
XMLHttpRequest and response handling are essential parts of AJAX. But we
still have to write our back end and extra JavaScript functions that will glue
things together. Let us first build a PHP back end that will give us recipe
details and comments on them. Below is the code in recipeHandler.inc.
php??”the file that will be invoked via index.php through AJAX.
ob_end_clean();
if (!$_REQUEST['what'] || $_REQUEST['what'] == 'show')
{
// Replace new lines with list item tags so that we can show
// a nice display
function splitToList($string)
{
return '
'.
Pages:
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254