hi everyone, i m very new to Ajax, and this is my first program in Ajax. I dont know what is wrong in the script. Please help me to find out the error, The main error is the value that i suppose to pass through url is not passing. thanking you in advance.
test.html
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<script language="javascript" type="text/javascript">
function ajaxFunction()
{
var ajaxRequest; // the variable that makes Ajax possible
try
{ //opera + firefox safari
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
try
{
ajaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
}
catch (e)
{
alert("Your browser is not support ajax");
return false;
}
}
//create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState ==4)
{
document.myform.name.value = ajaxRequest.responseText;
}
}
var empFirstName = document.getElementById('empFirstName').value;
var queryString = "?empFirstName="+empFirstName;
ajaxRequest.open("GET","test-ajax.php"+queryString, true);
ajaxRequest.send(null);
}
</script>
<form name="myform">
Employee First Name:<input type="text" id="empFirstName"></br>
<input type="button" onclick="ajaxFunction()" value="Test">
</form>
</BODY>
</HTML>
[/HTML]
my php file is
test-ajax.php
[PHP]<?php
$error = "";
include ("config.inc.php");
include ("connect.inc.php");
$empFirstName = $_GET['empFirstName'];
$sql = "SELECT * FROM userdetails wherer empFirstName='$empFirstName'";
$result = mysql_query($sql) or die(mysql_error());
if($result)
{
while($row=mysql_fetch_array($result))
{
echo "Employee Last Name: ".$row['empLastName'];
}
}
else
{
echo "Sorry";
}
?>[/PHP]
12 1882
Hi,
Are you getting the value for following line. -
-
var empFirstName = document.getElementById('empFirstName').value;
-
I mean are you sure that this variable is assigned properly and you are gettting the value of the textbox in this variable.
If not sure then use ALERT box after this line to check this variable. Or in any case get back here.
Regards,
RP
yes, i did not get this value through the URL. So, is there any problem, the way i assign the value of empFirstName, if yes pls tell me
waiting for your reply
Hi,
Are you getting the value for following line. -
-
var empFirstName = document.getElementById('empFirstName').value;
-
I mean are you sure that this variable is assigned properly and you are gettting the value of the textbox in this variable.
If not sure then use ALERT box after this line to check this variable. Or in any case get back here.
Regards,
RP
yes, i did not get this value through the URL. So, is there any problem, the way i assign the value of empFirstName, if yes pls tell me
waiting for your reply
Hi,
I've tried your code and it works fine... Sending the request and getting the output as required in my case.
Anyways, So there isn't any proble the way you are assigning the value. You wont get the value for this variable if you dont put anything in your textboxt.
i.e.
[HTML]
Employee First Name:<input type="text" id="empFirstName"></br>
[/HTML]
If you are entering any value and then clicking the buttong below it from where you are calling ajax function it works fine with my code. But in case you dont enter anything in TEXT box then you wont get value for your variable and then response from Ajax request.
Post back with your problem.
Regards,
RP
HI, thanks for the response, actually i was working on Safari browser, but when i try to run the program in IE 5+ its, saying that you browser is not support,
but when i try to run in mozila and safari, they dont show any result .. and in the url the value is not showing in the url
http://localhost/habsons_/test.html
before click in the button
but when i click its shows only http://localhost/habsons_/test.html? and no any kind of action. So can u tell me what is the exact problem
Hi,
I've tried your code and it works fine... Sending the request and getting the output as required in my case.
Anyways, So there isn't any proble the way you are assigning the value. You wont get the value for this variable if you dont put anything in your textboxt.
i.e.
[HTML]
Employee First Name:<input type="text" id="empFirstName"></br>
[/HTML]
If you are entering any value and then clicking the buttong below it from where you are calling ajax function it works fine with my code. But in case you dont enter anything in TEXT box then you wont get value for your variable and then response from Ajax request.
Post back with your problem.
Regards,
RP
gits 5,390
Expert Mod 4TB
you have a typo here: - ajaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
-
it should be: - ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
kind regards
A line you made wrong. -
jaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
-
//The ActiveXOhject spelling is wrong.
-
And you should change the coding pattern. -
if(typeof XMLHttpRequest!='undefined') ajaxRequest = new XMLHttpRequest();
-
else{
-
ajaxRequest = new ActiveXOhject("Microsoft.XMLHTTP");
-
if(ajaxRequest==null) ajaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
-
}
-
-
//the expression
-
ajaxRequest.readyState ==4 && ajaxRequest.status == 200
-
Now run the .php alone woth specified parameter.
And see whether it runs or not.
Debasis Jana
when i run the .php file along by passing the parameter, but when i access it from test.html file its not working. even the value is not passing through the url. i dont know what to do, can u code whole once again and i will copy from that ..
A line you made wrong. -
jaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
-
//The ActiveXOhject spelling is wrong.
-
And you should change the coding pattern. -
if(typeof XMLHttpRequest!='undefined') ajaxRequest = new XMLHttpRequest();
-
else{
-
ajaxRequest = new ActiveXOhject("Microsoft.XMLHTTP");
-
if(ajaxRequest==null) ajaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
-
}
-
-
//the expression
-
ajaxRequest.readyState ==4 && ajaxRequest.status == 200
-
Now run the .php alone woth specified parameter.
And see whether it runs or not.
Debasis Jana
when i run the .php file along by passing the parameter, but when i access it from test.html file its not working. even the value is not passing through the url. i dont know what to do, can u code whole once again and i will copy from that ..
You're trying to set the value of a form field called 'name', but this doesn't exist in your form.
when i run the .php file along by passing the parameter, but when i access it from test.html file its not working. even the value is not passing through the url. i dont know what to do, can u code whole once again and i will copy from that ..
Just what i told to do you first do that then tell us what's the problem?
Debasis Jana
[PHP]
$sql = "SELECT * FROM userdetails wherer empFirstName='$empFirstName'";
//check spelling of wehre
[/PHP]
You have mistake in your SQL statement as well check that as well
Anyways,
Your code is working fine with my machine(FC4/FF2)(WinXP/IE7-From network).... However i've added a textbox named 'name'-which is another textbox. And My PHP Scipt just echo backs whatever you are putting in first textbox and write it to the second one.
Regards,
RP
hi my name is bharath
how to connect ajax application to database using servlets? not with php or asp..
can u tell me plsssssssssssssssssssssssssssssss.....
.............................bharath.
hi my name is bharath
how to connect ajax application to database using servlets? not with php or asp..
can u tell me plsssssssssssssssssssssssssssssss.....
.............................bharath.
Servlets would be JSP, correct? The client-side code is pretty much the same.
By the way, I think you need to check your keyboard - your S and . keys seems to have got stuck!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dougwig |
last post by:
I'm trying to handle the scenario where a user's session times out and
and their ajax request triggers a redirection by the webserver (302
error?).
I'm using Prototype 1.4 and the my works great...
|
by: hardrock |
last post by:
Hello!
I'm working with the prototype library version 1.4.0 and having a
strange error lately. When I want to make an Ajax.Updater call, it
basically works. But as soon as I put the call into...
|
by: meltedown |
last post by:
This is supposed ot be an example:
http://www.ajaxtutorial.net/index.php/2006/11/30/simple-ajax-using-prototype-part-2/
It says :
This example is probably the simplest example you will ever...
|
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...
|
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= |
last post by:
Greetings! I was researching AJAX to provide a solution to displaying status
messages while a long process executed. I found several examples online and
was able to use their code to get a quick...
|
by: shivendravikramsingh |
last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
|
by: shaunwo |
last post by:
I'm an AJAX / DOM Novice (at best) and trying to figure out how to write the value to a couple input fields. I don't remember exactly where I got the ajax.js file I'm using from (went to the website...
|
by: RamananKalirajan |
last post by:
Hi those who were working in Ajax, will surely experienced with this problem. SOP - Single Origin Policy problem. I am doing a small work in Prototype Ajax. I did a sample work. When I am passing the...
|
by: cyqotiq |
last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet.
Second, let me state that this is not the typical "getElementById not working Firefox"...
|
by: javediq143 |
last post by:
Hi All,
This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |