Hit a real wall here.. I'm developing an App to drop into PhoneGap to put on iOS. Which only allows JS/HTML5/CSS3 to run native inside the app. So I've been using AJAX to get DB entries from my PHP. Problem is I wanted to have a dynamic canvas that displays a visual of my database info. My PHP can build javascript but I couldn't get it to run when it pop'd it into a Div tag. So I gave up an decided to just put the function in my HTML doc that build the AJAX request to the PHP for DB querries. Problem was I needed to get back a variable from PHP that contained the string that my Canvas function would parse to build an image. I tried hiding the data in a hidden field in the AJAX return the make the script in the header grab it and build the canvas but that never seemed to work. I'm guessing because the script had completed by the time the AJAX got back the data. (not sure though). Anywho so I decided to go with cookies. When my AJAX Querries the PHP the PHP built a cookie wit the data my Canvas Function needs. But the HTML page creating the AJAX request can't see the Cookie til I do a page refresh. This led me to creating a If/Else statement that on refresh of the page looks for the cookie if it sees it it goes to a branch that runs the DB AJAX call and runs the Canvas function if not it runs the AJAX DB Call and reloads the page. This is to avoid looping. Problem is it all works fine when my Alerts are in place. I put them there to make sure everything was working properly step-by-step. But when I take them out especially the ones related to the Reload/refresh of the page it throughs the page into an infinite loop. Its as if the script is runing so fast it does even catch that theres a new cookie present. Please see my code below.. Never mind my reload added an append to the URL I was thinking of using something like that to fork the refresh instead of the cookie since it wasn't working. What you think any suggestions.

PS- I can put in all the functions if that would help. But my testing seems to show that with the alert under ReloadPage() commented out the whole page goes into an infinte loop with it in it works fine.

<script type="text/javascript">
<!--
function checkcookie(){
//alert("func checkcookie-");
var BR = getCookie("brpar");
//alert("br-"+BR);
var BR = BR.split(", next cell dots ");
if(BR == ""){
//alert("No Cookie");
ajaxFunctionENG();
reloadPage();
}else if(BR != ""){
//alert("Cookie found");
ajaxFunctionENG();
canvas();
}
}
function reloadPage(){
//alert("reload next command");
//window.location.reload();
var url = location.href;
var status = "&status=1";
//alert("reload url-"+url+status);
window.location.assign(url+status);
}
//-->
</script>