473,725 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax - beginner level (Getting response from server)

23 New Member
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.XMLHT TP'); }
catch (e2)
{
try { test = new XMLHttpRequest( ); }
catch (e3) { test = false; }
}
}

test.onreadysta techange = function()
{
if(test.readySt ate == 4)
{
if(test.status == 200)
document.form1. pingtext=test.r esponseText;
else
document.form1. pingtext=test.s tatus;
}
};

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="submit Form()">
<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.
Nov 21 '07 #1
15 4196
gits
5,390 Recognized Expert Moderator Expert
hi ...

welcome to TSDN ...

you should pass GET as a string :)

Expand|Select|Wrap|Line Numbers
  1. test.open('GET', 'ping_test.php',  true);
kind regards
Nov 22 '07 #2
JohnDriver
23 New Member
hi ...

welcome to TSDN ...

you should pass GET as a string :)

Expand|Select|Wrap|Line Numbers
  1. test.open('GET', 'ping_test.php',  true);
kind regards
Hello,

Thanks though I get the same error - Error on Page which I click the button even after the changes done.
Nov 22 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
You need to set the value of the input text box:
Expand|Select|Wrap|Line Numbers
  1. document.form1.pingtext.value = test.responseText
Nov 22 '07 #4
gits
5,390 Recognized Expert Moderator Expert
You need to set the value of the input text box:
Expand|Select|Wrap|Line Numbers
  1. document.form1.pingtext.value = test.responseText
aaarghh :) ... i missed that ... of course the handling of the response is wrong ...

kind regards
Nov 22 '07 #5
JohnDriver
23 New Member
aaarghh :) ... i missed that ... of course the handling of the response is wrong ...

kind regards
Still didn't work, Sorry. I think its my bad luck :D

Best Regards...
Nov 22 '07 #6
gits
5,390 Recognized Expert Moderator Expert
hmmm ... it should work ... could you post your current code again? could you test it in FF and have a look at the javascript-console and post the error you get?

kind regards
Nov 22 '07 #7
JohnDriver
23 New Member
hmmm ... it should work ... could you post your current code again? could you test it in FF and have a look at the javascript-console and post the error you get?

kind regards
Sorry my bad. It happens sometimes that when I do so many edits to one file, it does not get refreshed at all and keeps on showing me same old errors. So I deleted that file and pasted the same code in a new file and it works!

Thank you for your quick reply. Hope I will be able to do some scripting in Ajax from now since now I have my first program running. Its something new to learn :)
Nov 22 '07 #8
gits
5,390 Recognized Expert Moderator Expert
glad to hear you got it working :) ... post back to the forum anytime you have more questions ...

kind regards
Nov 22 '07 #9
JohnDriver
23 New Member
glad to hear you got it working :) ... post back to the forum anytime you have more questions ...

kind regards
Hi Again,

Thank you for the help last time. I have another question please. The above code works fine except one thing. If I click on Ping button, the first time, it shows the ping results after properly pinging the machine but if I click on Ping again, the pinging does not happen - as in it does not go to the PHP page which pings the machine. However it does show the last ping results.

Is it because there is a browser cache which knows the last result from server?

I originally thought that everytime that button is clicked, it will call the PHP to check whether the machine is ping-able or not.

Thank you.
- John
Nov 25 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1178
by: Terry Smith | last post by:
I have individual Javascript files at the component level for components that need to make AJAX calls to the server. The server returns a list of XML elements with the name of the control whose contents will be updated and the HTML of the new content. My client-side callback handler is generic in handling this XML, and I don't want to copy it to all the individual component-level Javascript files. I would like to have it in a common...
5
1766
by: darrel | last post by:
I've been playing with prototype.js and scriptaculous to create some nice drag-and-drop interaction on my applications GUI. That's working well. Now I want to take the next step and start passing data back and forth between my page and the server via AJAX. In terms of .net, can someone give me the overall concept? Normally, I'd have a function in my codebehind that grabs a dataset and then binds that to a control on my aspx page.
4
7472
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole new page that should replace an existing one. I.e when we issue an Ajax request we don't know what will be returned and analyze the response to act accordingly. Now, the way to replace the current document with a new one used to be easy and...
4
1361
by: pbd22 | last post by:
Hi. I have an ajax question. I am wondering if it is possible to get the response from a method within a given page, and that function alone? Traditionally, I have been getting the response from the Page_Load method of the targeted page, but now I want the response from a particular method on the target page: Public Sub SomeCallback(ByVal sender As Object, ByVal e As EventArgs)
1
4032
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
1
2053
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped working. Any ideas? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="default-ajax.aspx.vb" Inherits="pages_verify_groups_Default" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
2255
by: malcster2 | last post by:
hello, i am a beginner to ajax. i have created a mysql database, which i would like to access from a web page. i have created 3 files, a html to display the data, a php file to extract the data, and a javascript file to to the clever stuff. when i access the html page, all the data is displayed correcty, but if i add or delete any records, and press the button i have created to refresh the data(without reloading), the data doesn't change....
7
6661
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.