dongzhazhuo0572 2011-11-09 07:30
浏览 20

我的ajax_framework代码有什么问题?

When I use action="updatebonpen.php" directly in the html page, it updates the database well. Now, I tried using jQuery to update my database, it'll just keep showing "Adding, please wait..." without updating the database.

I have used this same codes in another site earlier and it is working very fine there. Below is the code:

/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
  var request_type;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
    request_type = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    request_type = new XMLHttpRequest();
  }
  return request_type;
}

var http = createObject();

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
  // Optional: Show a waiting message in the layer with ID login_response
  document.getElementById('insert_response').innerHTML = "Adding, please wait..."
  // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
  var bonpen= encodeURI(document.getElementById('bonpen').value);
  var points= encodeURI(document.getElementById('points').value);
  var reason= encodeURI(document.getElementById('reason').value);
  var comment = encodeURI(document.getElementById('comment').value);
  var username = encodeURI(document.getElementById('username').value);
  // Set te random number to add to URL request
  nocache = Math.random();
  // Pass the login variables like URL variable
  http.open('get', 'updatebonpen.php?bonpen=' +bonpen+'&points=' +points+'&reason=' +reason+'&comment=' +comment+'&username=' +username+'&nocache = '+nocache);
  http.onreadystatechange = insertReply;
  http.send(null);
}
function insertReply() {
  if(http.readyState == 4){
    var response = http.responseText;
    // else if login is ok show a message: "Site added+ site URL".
    document.getElementById('insert_response').innerHTML = 'Ok.'+response;
  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题