2

我有一些 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";
?>

想法?

4

3 回答 3

0

这是什么?

"&state=accept$p=a9dafdd0fe68c6f64841e265e1c8832a",

...应该是这样的

"&state=accept&p=a9dafdd0fe68c6f64841e265e1c8832a",
于 2012-10-20T11:33:45.037 回答
0

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

于 2012-10-20T11:39:11.123 回答
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;
})
于 2012-10-20T11:26:34.650 回答