473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to get data from ajax responseText. Here i use three parts.

In first part
1.html..i have one combo box
and code as below
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form name="ajax">
  3. <select  onchange="request()" id="cmbnum">
  4. <option value=1>ONE</option>
  5. <option value=2>TWO</option>
  6. <option value=3>THREE</option>
  7. </select></form>
  8.  
this java script part.i have function as below.
when i am using the syntax it return only empty alert....
Expand|Select|Wrap|Line Numbers
  1. function request()
  2. {
  3.     optnum=document.getElementById("cmbnum").value;
  4.  
  5.     url="ajax\response.php?num="+optnum;
  6.  
  7.  
  8.  
  9. xmlhttp.onreadystatechange=function()
  10.  {
  11.    if(xmlhttp.readyState==4 && xmlhttp.status==200 )
  12.      {
  13.  
  14.        ajaxres=xmlhttp.responseText;
  15.     document.getElementById("sample").innerHTML=ajaxres;
  16.     }
  17.  }
  18. xmlhttp.open("GET",url,true);
  19.  xmlhttp.send();
  20. }
  21.  
this php part..
Expand|Select|Wrap|Line Numbers
  1. if(isset($_REQUEST['num']))
  2.  
  3.     switch($_REQUEST['num'])
  4.     {
  5.         case 1:
  6.         echo "ONE";
  7.         break;
  8.         case 2:
  9.         echo "TWO";
  10.         break;
  11.  
  12.     }
  13.  
  14. }
  15.  
Apr 21 '12 #1
6 3941
Dormilich
8,658 Expert Mod 8TB
where is the part where you define the XMLHttpRequest object?
Apr 22 '12 #2
i include this as separate file named ajaxex.js in the function request()..
Expand|Select|Wrap|Line Numbers
  1. try
  2.     alert("hai");
  3.     xmlhttp=new XMLHttpRequest();
  4. }
  5. catch(e)
  6. {
  7.     try
  8.     {alert("hai");
  9.      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  10.     }
  11.     catch(e)
  12.     {
  13.         try
  14.         {alert("hai");
  15.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  16.         }
  17.         catch(e)
  18.         {
  19.             xmlhttp=null;
  20.             alert("ur browser is not work");
  21.         }
  22.     }
  23. }
  24.  
  25.  
Apr 22 '12 #3
Dormilich
8,658 Expert Mod 8TB
i include this as separate file named ajaxex.js in the function request()
how do you do that exactly?

did you verify that all your variables/parameters are set correctly?
Apr 22 '12 #4
by using the statement below i include the file in these file
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript" src="ajaxex.js">
  2. </script>
when i select anything from list box,suppose if it is one means it should display as ONE.When i simply give echo statement in php part it display back as alert message.but the code inside if statement is not work.so only i doesn't return anything to response text..
what i need to do now..
Apr 30 '12 #5
Dormilich
8,658 Expert Mod 8TB
do you have a live page?
Apr 30 '12 #6
My coding is work.. with slight modification in php part and in <option> tag.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     $sam=$_REQUEST['num'];
  4.  
  5.     switch($sam)
  6.     {
  7.         case "ONE":
  8.         echo "ONE";
  9.         break;
  10.         case "TWO":
  11.         echo "TWO";
  12.         break;
  13.         case "THREE":
  14.         echo "THREE";
  15.         break;
  16.  
  17.     }
  18.  
  19. ?>
  20.  
  21. <form name="ajax">
  22. <select  onchange="javascript:request()" id="cmbnum">
  23. <option value="ONE">ONE</option>
  24. <option value="TWO">TWO</option>
  25. <option value="THREE">THREE</option>
  26. </select>
  27.  
here i get get alert when i select item in list box..
thanks for ur help..
Apr 30 '12 #7

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

Similar topics

5
by: Nancy | last post by:
I have two tables: TblCourse CourseID CourseName TblClass ClassID CourseID ClassDate
1
by: yasinahmad | last post by:
Hi every one I have three tables 1-students 2-books 3-pens I wont to make report by data report to show tables like this student name
3
by: Snt | last post by:
Hi! I am trying to get AJAX working on multiple browsers and am having a problem with Firefox. I have the following code: function handleState3(){ switch(http.readyState) { case 0: //...
1
by: abrtlt | last post by:
I have a simple PHP script that sends a string to XMLHttpRequestObject.responseText. responseText as received from the PHP script begins with 2 extra newline characters (\n\nMyString): <?php...
3
by: alan.chambers | last post by:
I am new to C++/CLI. I want to do a very simple thing. In other C++ applications, my forms have always been 'context free' in the sense that I pass them a temporary copy of the data for them to...
1
by: Pugi! | last post by:
Currently I am using a responsexml for an xmlhttprequest. The information is then processed by javascript : elements are created with attributes incl events using setAttribute; in other words I...
4
by: techusky | last post by:
I am making a website for a newspaper, and I am having difficulty figuring out how to take a string (the body of an article) and break it up into three new strings so that I can display them in the...
6
by: lazukars | last post by:
Hi, I am attempting an ajax request. I am using PHP serverside. Below is what the response text should be. ajaxRequest.responseText ="{username_is_taken : "This username has been taken",}" ...
4
RamananKalirajan
by: RamananKalirajan | last post by:
Hi All, I am using Ajax inorder to retrieve a data from the db which is an xml and i am parsing the responseText into an xml. the code what i had tried is working well with IE, but the...
4
maliksleo
by: maliksleo | last post by:
Hi i want to give the background to all of my buttons in my web. I did the following in style sheet. input { background-color: black; color:White; } but now my requirement is changed and...
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.