gpt4 book ai didi

javascript - Ajax 附加到当前 URL 末尾而不是提供的文件名

转载 作者:行者123 更新时间:2023-11-28 19:45:52 25 4
gpt4 key购买 nike

我遇到的问题是 ajax 只是将变量附加到当前 URL 的末尾。我需要它指向 ProHost.php。

我正在使用这里的教程 tutorial

我让它工作的方式是表单中的onSubmit="return validateInput();验证我的输入,然后调用function ajaxFunction()发送数据到我的 php 文件 ProHost.php

但是现在 ajax 就是这么做的

NewHost.php?FName=d&LName=d&email=samesc%40yahoo.com&BirthDate=2014-06-8&Pass=s&PassRe=s

当它应该看起来像这样

ProHost.php?FName=d&LName=d&email=samesc%40yahoo.com&BirthDate=2014-06-18&Pass=s&PassRe=s

如果我自己编辑 URL (ProHost.php?FName=d&LName=...),PHP 文件的报告就像在空白页面上使用纯文本一样。

这是 HTML 表单:

<form  action=""  method ="get" onSubmit="return validateInput(); " >
<p id="demo" style="text-align: center">&hellip;</p>
First Name: <input Id="FName" name="FName" type="text" required placeholder="john" size="35" value="d" >

Last Name: <input Id="LName" name="LName" type="text" required placeholder="Smith" size="35" value="d">

Email: <input Id="email" name="email" type="email" required placeholder="John@Smith.com" size="35" >

Birth Date: <input Id="BirthDate" name="BirthDate" type="date" required min="1900-01-01" >

Password: <<input Id="Pass" name="Pass" type="password" required size="35" placeholder="Secret" >

Retype Password: <input Id="PassRe" name="PassRe" type="password" required size="35" placeholder="Secret" >
<input type="reset" class="Button" value="Clear" name="ResetBtn">
<input type="submit" class="Button" value="Submit">
<input id="clickMe" type="button" value="clickme" onclick="doFunction();" />
</form>

这是脚本:

<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("Your browser broke! Please use a current web browser");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('demo');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.

//Mine
var Fname = document.getElementById("FName").value;
var Lname = document.getElementById("LName").value;
var BirthDate = document.getElementById("BirthDate").value;
var email = document.getElementById("email").value;
var Pass = document.getElementById("Pass").value;

var queryString = "?Fname=" + Fname + "&Lanme=" + LName +
"&BirthDate=" + BirthDate + "&EMail=" + email + "&Pass=" + Pass;
ajaxRequest.open("GET", "ProHost.php" + queryString, true);
ajaxRequest.send(null);
return false
}

最佳答案

尝试更改此行:

ajaxRequest.open("GET", "ProHost.php" + queryString, true);

对此:

ajaxRequest.open("GET", "/ProHost.php" + queryString, true);

与/

关于javascript - Ajax 附加到当前 URL 末尾而不是提供的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24294129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com