SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 248 | Next

Nirav Mehta

"Mobile Web Development"

If it is, only then we make the request to get the recipe.
At the start of our JavaScript, we have initialized two variables??”num and
reqNum. Variable num will store the index of the current recipe and reqNum is
the index of the requested recipe.
2. What remains is to set the num to reqNum once the requested recipe is
received! Let us write a function that does this in recipe.inc.php. We will
then call this function once we get the XHR response. Below is the code.
function ResultProcessed()
{
num = reqNum;
}
3. Next, let us modify frost.js ProcessXHR() to call our function once
the response is processed. This means once the recipe is displayed,
ResultProcessed() will be called. If you are going to use frost.js
in other pages, you should make sure that you have a function named
ResultProcessed() on the page, otherwise it will throw up a JavaScript error.
function ProcessXHR(xmlHttpReq, responsediv, addcontent){
var responseText = xmlHttpReq.responseText ?
xmlHttpReq.responseText : '';
if(addcontent){document.getElementById(responsediv)
.innerHTML += responseText;}
Mobile AJAX
[ 194 ]
else {document.getElementById(responsediv).


Pages:
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260