Wednesday, August 6, 2008

AJAX and Smoothbox issues

Back to a situation today where the front end developer and I both think it's the "other" person who needs to fix a problem between ajax and smoothbox.

The entire process
User "drags" an item into a "box".
The JavaScript then runs my script thusly:
pickMovie(item.id);
Then my script does this (shortened for brevity's sake):
function pickMovie(int) {
xmlHttpPoll=GetXmlHttpObjecta()
var url="/pickmovie.php?element_id="+int
url=url+"&sid="+Math.random()
xmlHttpPoll.onreadystatechange=stateChangeda
xmlHttpPoll.open("GET",url,true)
xmlHttpPoll.send(null)
}
Basically all it does is capture the ID, and send it to the PHP page. At the PHP page, it does a nice big request from the database, and returns the following:

<li><a href="http://www.blogger.com/titleinfo.php
?id=1&keepThis=true&TB_iframe=true&height=609
&width=761" class="smoothbox">Title</a></li>

So now this is returned to the JavaScript to output like:
function stateChangeda(){
if (xmlHttpPoll.readyState==4 || xmlHttpPoll.readyState=="complete"){
$('demo').setStyle('display', 'none');
$('searchResultsCont').setStyle('display', 'block');
var resultsList = xmlHttpPoll.responseText;
var amp ="&";
var updatedResultsList = resultsList.replace(/&/g,amp);
$('searchResultsUl').innerHTML=updatedResultsList;
}
}
Pretty simple? The output we found had all the &'s turned into &'s. No idea why, but so hence why the front end developer did the replace here.

Doesn't work.. I mean the link works, but it doesn't use the smoothbox script. It works elsewhere on the page, where it is simply written, but not when returned through AJAX.

I'll post more as we learn more!

BFN

No comments: