Ajax - 初学者级别(从服务器获取响应) [英] Ajax - beginner level (Getting response from server)
问题描述
你好
我正在学习Ajax,我正在按照找到的教程,但由于某种原因,我的代码无效。我想我在下面发布的代码中遗漏了一些东西。请看看并告诉我。
[HTML]< html>
< head>
<脚本>
函数submitForm()
{
var test;
try {test = new ActiveXObject(' 'MSXML2.XMLHTTP''); }
catch(e)
{
try {test = new ActiveXObject(''Microsoft.XMLHTTP''); }
catch(e2)
{
try {test = new XMLHttpRequest(); }
catch(e3){test = false; }
}
}
test.onreadystatechange = function()
{
if(test.readyState == 4)
{
if(test.status == 200)
文件。 form1.pingtext = test.responseText;
else
document.form1.pingtext = test.status;
}
};
test.open(GET," ping_test.php",true);
test.send(null);
}
< / script>
< / head>
< body>
< FORM method =" POST"名称= QUOT; form1的" action ="">
< INPUT type =" BUTTON" value =" Ping the machine" onclick =" submitForm()">
< INPUT type =" text"命名= QUOT; pingtext" value ="">
< / FORM>
< / body>
< / html> [/ HTML ]
ping_test.php具有以下代码:
[PHP]<?php
$ ec =`ping 127.0.0.1`;
echo"< pre> $ ec< / pre>" ;;
?> [/ PHP]
我想做的是采取来自用户的IP地址并ping它。并在html页面本身的div或textarea中显示ping结果,而无需转到另一个页面。但要测试,我使用127.0.0.1并ping它。但是,当我点击提交 - 它在页面上显示错误。我不知道正确的语法。有人能让我知道我哪里出错吗?
如果有人能告诉我如何接受用户输入并通过它?我只想学习如何在初级水平上使用它。
谢谢。
ec =`ping 127.0.0.1`;
echo"< pre>
ec< / pre>" ;;
?> [/ PHP]
我想要做的是从用户那里取一个IP地址并ping它。并在html页面本身的div或textarea中显示ping结果,而无需转到另一个页面。但要测试,我使用127.0.0.1并ping它。但是,当我点击提交 - 它在页面上显示错误。我不知道正确的语法。有人能让我知道我哪里出错吗?
如果有人能告诉我如何接受用户输入并通过它?我只是想学习如何在初级水平上使用它。
谢谢。
嗨...
欢迎来到TSDN ...
你应该把GET作为字符串传递:)
展开 | 选择 | Wrap | 行号< /跨度>
Hello
I am learning Ajax and I am following the tutorials found but for some reason, my code is not working. I think I am missing something in the code that I am posting below. Please have a look and let me know.
[HTML]<html>
<head>
<script>
function submitForm()
{
var test;
try { test = new ActiveXObject(''Msxml2.XMLHTTP''); }
catch (e)
{
try { test = new ActiveXObject(''Microsoft.XMLHTTP''); }
catch (e2)
{
try { test = new XMLHttpRequest(); }
catch (e3) { test = false; }
}
}
test.onreadystatechange = function()
{
if(test.readyState == 4)
{
if(test.status == 200)
document.form1.pingtext=test.responseText;
else
document.form1.pingtext=test.status;
}
};
test.open(GET, "ping_test.php", true);
test.send(null);
}
</script>
</head>
<body>
<FORM method="POST" name="form1" action="">
<INPUT type="BUTTON" value="Ping the machine" onclick="submitForm()">
<INPUT type="text" name="pingtext" value="">
</FORM>
</body>
</html>[/HTML]
The ping_test.php has the following code:
[PHP]<?php
$ec =`ping 127.0.0.1`;
echo "<pre> $ec </pre>";
?>[/PHP]
What I want to do is to take an IP Address from the user and ping it. And show the ping results in a div or a textarea on the html page itself without going to another page. But to test, I am using 127.0.0.1 and pinging it. But when I click on Submit - It says Error on Page. I don''t know the correct syntax. Can someone let me know where I am going wrong, please?
If someone can tell me how to take user input and pass it also? I just want to learn how to use it on a beginner level.
Thank you.解决方案ec =`ping 127.0.0.1`;
echo "<pre>
ec </pre>";
?>[/PHP]
What I want to do is to take an IP Address from the user and ping it. And show the ping results in a div or a textarea on the html page itself without going to another page. But to test, I am using 127.0.0.1 and pinging it. But when I click on Submit - It says Error on Page. I don''t know the correct syntax. Can someone let me know where I am going wrong, please?
If someone can tell me how to take user input and pass it also? I just want to learn how to use it on a beginner level.
Thank you.
hi ...
welcome to TSDN ...
you should pass GET as a string :)
Expand|Select|Wrap|Line Numbers
这篇关于Ajax - 初学者级别(从服务器获取响应)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文