AJAX奇怪的重定向?

时间:2012-10-20 11:25:17

标签: php ajax

我有一些AJAX代码在按下按钮时重定向。

重定向到members.php

这是AJAX代码:

<script language="javascript" type="text/javascript">

    function ajaxFunction(){
            var ajaxRequest;  // The variable that makes Ajax possible!

            try{
                // Opera 8.0+, Firefox, Safari
                ajaxRequest = new XMLHttpRequest();
            } catch (e){
                // Internet Explorer Browsers
                try{
                    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try{
                        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e){
                        // Something went wrong
                        alert("Please update your browser.");
                        return false;
                    }
                }
            }
        }

        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            // We still need to write some code here
                if(ajaxRequest.readyState == 4){
                    // Get the data from the server's response
                    response = ajaxRequest.responseText;
                }
        }
        ajaxRequest.open("GET", "accept.php?id=<?php echo $articleid; ?>&state=accept$p=a9dafdd0fe68c6f64841e265e1c8832a", true);
        ajaxRequest.send(null);                 
    }       

</script>

这是按钮:

<input type="submit" onChange="ajaxFunction();" />

这是accept.php的内容:

<?php
    echo "ACCEPTED";
?>

想法?

3 个答案:

答案 0 :(得分:0)

<input type="submit" onChange="ajaxFunction();" />

should be

<input type="submit" onclick="ajaxFunction();" />

并在功能结束时使用return false;

或者您可以使用简单的jquery

$("#submit").click(function(){
// or $("#form").submit(function(){
$.get("accept.php?id=<?php echo $articleid; 
?>&state=accept&p=a9dafdd0fe68c6f64841e265e1c8832a",function(data){
rasponce=data;
  })

 return false;
})

答案 1 :(得分:0)

这是什么?

"&state=accept$p=a9dafdd0fe68c6f64841e265e1c8832a",

......应该是

"&state=accept&p=a9dafdd0fe68c6f64841e265e1c8832a",

答案 2 :(得分:0)

members.php是您表单上的操作?如果是这样,我将删除该操作并再次尝试,看看会发生什么。