It's a weird doubt, but it goes....
I have a button in a page, that makes a Ajax request, and when i have the answer, I write it to the page and then it's called a function to adjust Page Elements. When i click the button the first time, this function isn't called, but in the next request it is.
But...if I place a alert in the scope of the function, when i make the same firs开发者_如何转开发t ajax request and wait for the answer to call the function, it displays the content of the alert and adjust my page elements.
Well...i don't see any logic in that, but if this ring's a bell to anyone, I apreciate the help.
EDIT:
function HandleResponseCellVehicleReport()
{
if (XmlHttp.readyState == 4) {
if (XmlHttp.status == 200) {
WriteCellVehicleReport(XmlHttp.responseText);
}
else {
alert("Problema: " + XmlHttp.statusText);
}
}
}
function WriteReport(myJSONtext) {
(....)
EndLoad(document);
EnableButtons(document);
adjustPageElements(pageId,document);
}
function adjustPageElements(client, __document) {
var viewportwidth;
var viewportheight;
if (!__document) {__document = document;}
(....)
}
I place the alert in the beginning of adjustPageElements function.
Thanks
I think this is because you ajax call goes Asynchronous, the content isn't yet fetched from the backend script before you try to put it in a page element. Take a look at this. If you make a synchronous ajax call the browser waits until the content is parsed back. also see this article
精彩评论