问题描述:

I was wondering if someone could help me here. My code is working just fine in all browsers, but once I get to my facebook app page none of my divs showMsg, showMsg2, try or try1 are showing up. Can someone please help me? Here's the code....

Actually I've since fixed it, I just got rid of && xmlhttp.status==200

<script type=text/javascript>

function get_radio_value()

{

var xmlhttp;

if (window.XMLHttpRequest)

{// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

}

else

{// code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

for (var i=0; i < document.plz.myGuess.length; i++)

{

if (document.plz.myGuess[i].checked)

{

var rad_val = document.plz.myGuess[i].value;

var rightAnswer = document.plz.here.value;

var entryID = document.plz.entryid.value;

if (Number(rad_val) == Number(rightAnswer))

{var points=1;

xmlhttp.onreadystatechange=function()

{

if (xmlhttp.readyState==4 && xmlhttp.status==200)

{

document.getElementById('showMsg').innerHTML=xmlhttp.responseText;

document.getElementById('showMsg').style.display = 'block';

document.getElementById('try').style.visibility = 'visible';

}}}

else {

var points=0;

xmlhttp.onreadystatechange=function()

{

if (xmlhttp.readyState==4 && xmlhttp.status==200)

{

document.getElementById('showMsg2').innerHTML=xmlhttp.responseText;

document.getElementById('showMsg2').style.display = 'block';

document.getElementById('try1').style.visibility = 'visible';

}}}}}

xmlhttp.open("GET","/script/facebook/fb_question.php?correct=" + points + "&entryid=" + entryID ,true);

xmlhttp.send();

}

</script>

{exp:weblog:entries weblog="fbqs" orderby="date" sort="desc" limit="1" disable="member_data|trackbacks"}

<div style="line-height:150%">{fbquestion} <br /><br/>

<form name="plz" >

<input type="hidden" id='here' value='{correct}' />

<input type="hidden" id='entryid' value='{entry_id}' />

<input type="radio" name='myGuess' value='1' checked="checked" /> {opta}<br />

<input type="radio" name='myGuess' value='2' /> {optb}<br />

<input type="radio" name='myGuess' value='3' /> {optc} <br />

<input type="radio" name='myGuess' value='4' /> {optd} <br/>

<input type="radio" name='myGuess' value='5' /> {opte}<br/><br/>

<input type='button' onClick='get_radio_value()' value='Guess' >

</form>

<br>

<div id="showMsg" style="display:none; background:url(/images/correct2.gif) no-repeat ;width: 200px; height: 25px;"></div>

<div id="showMsg2" style="display:none; background:url(/images/incorrect2.gif) no-repeat ;width: 200px; height: 25px;"></div>

<br>

<div id="try" style="visibility:hidden;">Read more about the answer <a href="{articleurl}">{article}</a></div>

<div id="try1" style="visibility:hidden;">Find the correct answer here <a href="{articleurl}">{article}</a></div>

{/exp:weblog:entries}

网友答案:

Your divs only appear if your ajax call returns a status of 200, so the most likely explanation is that you are receiving some other status (404 maybe?). Try displaying the actual status you receive, and check your website error logs for hints.

相关阅读:
Top