无法使用JavaScript或Ajax和文本显示相同的页面 [英] having trouble using JavaScript or Ajax and text display the same page
本文介绍了无法使用JavaScript或Ajax和文本显示相同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有错误不知道错误在哪里
无法使用JavaScript或Ajax和文本显示同一页面
请帮我改正错误
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>弹出范例< / title>
< script src =// code.jquery.com/jquery-1.11.2.min.js\">< ;; script>
< script type =text / javascript>
document.getElementById('myform')。addEventListener(submit,upload);
函数上传()
{
var xhr = new XMLHttpRequest();
xhr.open(POST,/ upload.php,true);
{
var formdata = new formData(myform);
xhr.send(formdata);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4&& xhr.status == 200)
{
/ /一些代码来检查提交是否成功
url = xhr.responseText();
if(url =='failed')
Console.log('upload failed'); //为失败做点什么
else
document.getElementById('urlBox')。innerHTML = url;
}
};返回false;
}
< / script>
< / head>
< body>
$ b< form id =myformmethod =POSTaction =<?php($ _SERVER [PHP_SELF]); ?>>
< p>选择了网址:
< select size =1name =D1>
< option value =google_drive> google drive< / option>
< option value =clody> clody< / option>
< / select>
< input type =textname =T1size =40>
< input type =submitvalue =goname =B1>
< input type =resetvalue =resetname =B2>
< / p>
< / form>
< / body>
< / html>
和这个upload.php文件
<$ p $($ _ POST ['D1'])&&!empty($ _ POST ['T1'])){$ b $
<?php
if b $ providers = array(
'google_drive'=>'Goole drive ^ https://drive.google.com/file/d/ {replace} / view',
'clody'=> ;'Cloudy ^ https://www.cloudy.ec/embed.php?id = {replace}'
);
if(isset($ providers [$ _ POST ['D1']])){
$ url = str_replace('{replace}',$ _POST ['T1 '],$ providers [$ _ POST ['D1']]);
echo$ url;
}
}
else {
echofailed;
}
?>
,谢谢大家
解决您可以尝试替换这一行:
< form id =myformmethod = POSTaction =<?php($ _SERVER [PHP_SELF]); ?>>
为此:
($ _SERVER [PHP_SELF]);?>>
不同之处在于您的操作。您没有使用
I'm having mistakes do not know where error
Having trouble using JavaScript or Ajax and text display the same page
Please help me in the wrong reform
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pop up example</title>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
document.getElementById('myform').addEventListener("submit",upload);
function upload()
{
var xhr = new XMLHttpRequest();
xhr.open("POST","/upload.php",true);
{
var formdata = new formData(myform);
xhr.send(formdata);
}
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200)
{
//some code to check if submission succeeded
url = xhr.responseText();
if(url == 'failed')
Console.log('upload failed'); // do something for failure
else
document.getElementById('urlBox').innerHTML = url;
}
}; return false;
}
</script>
</head>
<body>
<form id="myform" method="POST" action=<?php ($_SERVER["PHP_SELF"]); ?>>
<p>chose url:
<select size="1" name="D1">
<option value="google_drive">google drive</option>
<option value="clody">clody</option>
</select>
<input type="text" name="T1" size="40">
<input type="submit" value="go" name="B1">
<input type="reset" value="reset" name="B2">
</p>
</form>
</body>
</html>
and this upload.php file
<?php
if(!empty($_POST['D1']) && !empty($_POST['T1'])){
$providers = array(
'google_drive' => 'Goole drive^https://drive.google.com/file/d/{replace}/view',
'clody' => 'Cloudy^https://www.cloudy.ec/embed.php?id={replace}'
);
if(isset($providers[$_POST['D1']])){
$url = str_replace('{replace}', $_POST['T1'], $providers[$_POST['D1']]);
echo "$url";
}
}
else{
echo "failed";
}
?>
and thank you all
解决方案
You can try replace this line:
<form id="myform" method="POST" action=<?php ($_SERVER["PHP_SELF"]); ?>>
For this:
<form id="myform" method="POST" action="<?php ($_SERVER["PHP_SELF"]); ?>">
The differece is in your action. You're not using ""
这篇关于无法使用JavaScript或Ajax和文本显示相同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文