-1

我正在尝试将数据发送到我拥有的 MYSQL php 脚本(有效),并且该脚本“回显”我想要的任何内容。脚本 php 文件完全正常工作,我可以选择在成功时回显的内容。但现在我想尝试从 HTML 切换到 Javascript 来替换没有页面加载的 div。

也许我现在使用的脚本是错误的脚本。

页面看起来像这样

<div id="Wrapper"> 
 <div id="std_img"
  //Here i have a img and a form with a submit button that sends the input data to my phpfile. 
 </div>


</div>

现在我想做的是替换取决于回声。可以说我回显了 div id。所以它会隐藏和显示

这是我的脚本到目前为止的样子。

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
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("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('ajaxDiv');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }

    var sex = document.getElementById('vipcode').value;
    var sex = document.getElementById('userid').value;
    var sex = document.getElementById('username').value;
    var queryString = "?vipcode=" + vipcode + "&username=" + username + "&userid=" + userid;
    ajaxRequest.open("GET","<?php echo plugins_url('valdate.php', __FILE__) ?> " + queryString, true);
    ajaxRequest.send(null); 
}

//-->
</script>





<form name="activatevip">
 <input name="vipcode" id="vipcode" type="text" placeholder="Write code here">
 <input class='button-primary' type='button' onclick='ajaxFunction()' value='Activate' />
<p>
    <input type="hidden" id="userid" value="<?php echo $current_user->ID ?>">
  <input type="hidden" id="username" value="<?php echo $current_user->user_login ?>">
  </p>

</form>

<div id='ajaxDiv'>ECHO is shown here</div> // is there a way of insted display an output to replace an div?
4

1 回答 1

1

这是不正确的。

var sex = document.getElementById('vipcode').value;
var sex = document.getElementById('userid').value;
var sex = document.getElementById('username').value;

您不能使用相同的变量名称。将它们更改为vipcode, userid,username

var vipcode = document.getElementById('vipcode').value;
var userid = document.getElementById('userid').value;
var username = document.getElementById('username').value;
var queryString = "?vipcode=" + vipcode + "&username=" + username + "&userid=" + userid;

PS:我喜欢你的变量名,sex. 光滑的。但很遗憾看到它走了。

于 2013-11-02T16:20:09.463 回答