elliott.david 2011-03-31 01:56 采纳率: 25%
浏览 491

ajax发送请求两次

Example URL: http://twitter.realgamingreview.com/index.php

Edit: forgot to mention: use the test sign in: test/test for username/password.

I am attempting to do a simple AJAX request to retrieve some data from a database. The target file, serverTime.php, seems to be working perfectly; it inserts the desired data and returns the desired responseText.

However, the request seems to be firing twice. This is clear when I step through the JavaScript using Firebug. This causes the page to 'reset' (not exactly sure), such that my cursor loses focus from its current textbox, which is a new problem. The URL also says, "localhost/twitter/index.php?message=", even if my message is not actually empty. I want to fix this fairly minor problem before something major comes of it.

The JavaScript is below. ajaxRequest is my XMLHTTPRequest object. Any help is appreciated!

//Create a function that will receive data sent form the server
ajaxRequest.onreadystatechange = function(){
    if (ajaxRequest.readyState == 4){
        document.getElementById('output').innerHTML = ajaxRequest.responseText;
    }
}
// build query string
var message = document.myForm.message.value;
var queryString = "message=" + message;

    //send AJAX request
    ajaxRequest.open("GET", "serverTime.php" + "?" + queryString, true);

    ajaxRequest.send(null);

Thanks,

Paragon

  • 写回答

3条回答 默认 最新

  • weixin_33714884 2011-03-31 03:19
    关注

    I've seen this many times, and for me it's always been firebug. Try TURNING OFF firebug and submit the request again. Use fiddler or some other means to verify the request only executed once.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题