开发者

If response: 1 then window.parent

I am using this script to insert comment to the database:

var http = createObject();
var nocache = 0;
function insert() {
  document.getElementById('insert_response').innerHTML = "To Sek .. "
  var fID= encodeURI(document.getElementById('fID').value);
  var kommentar= encodeURI(document.getElementById('kommentar').value);
  nocache = Math.random();
  http.open('get', 'insert.php?fID='+fID+'&kommentar=' +kommentar+'&nocache = '+nocache);
  http.onreadystatechange = insertRe开发者_开发知识库ply;
  http.send(null);
}
function insertReply() {
  if(http.readyState == 4){
  var response = http.responseText;
  document.getElementById('insert_response').innerHTML = ''+response;
  }
} 

Right now it innerHTML out the response text, that comes from insert.php.

But inside insert.php, I have setted up some "restrictions" in PHP like if empty, if double post etc. etc. I can therefore not place in:

window.parent.showMessage("Video Is OK");
//after
if (http.readystate == 4)..

So I would like to do another function to this script, that checks If the div box #box is containing 1, then:

window.parent.showMessage("Video Is OK");

How can I do that?

Thanks


Are you passing any errors back to the user (e.g. on double posts, empty posts, too long posts)? If you are, and you don't pass anything back on success you could check the length of the response and show your "Video IS OK" message if the length is zero:

if(http.readyState == 4) {
  var response = http.responseText;
  if (response.length > 0)  {
    // success
    window.parent.showMessage("Video Is OK");
  } else {
    // something went wrong, show error message
    document.getElementById('insert_response').innerHTML = response;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜