473,394 Members | 1,694 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,394 software developers and data experts.

PHP/AJAX Probelm

384 256MB
Maybe this should be moved to the Javascript/AJAX forum!

I have the below snippets of code, the problem is i can't get status to pass into the changeCaseStatus.php page, it just gives a blank value all the time???

show.php
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.     var loading_img = \'../../images/layout/loading.gif\';
  3.     var loading_msg = \' Loading Data...\';
  4.     var xmlhttp_obj = false;//create the XMLHttpRequest
  5.  
  6.     function ewd_xmlhttp()
  7.     {
  8.         if (window.XMLHttpRequest)
  9.         { // if Mozilla, Safari etc
  10.             xmlhttp_obj = new XMLHttpRequest();
  11.         }
  12.         else if (window.ActiveXObject)
  13.         { // if IE
  14.             try
  15.             {
  16.                 xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");
  17.             }
  18.             catch (e)
  19.             {
  20.                 try
  21.                 {
  22.                     xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
  23.                 }
  24.                 catch (e)
  25.                 {
  26.  
  27.                 }
  28.             }
  29.         }
  30.         else
  31.         {
  32.             xmlhttp_obj = false;
  33.         }
  34.  
  35.         return xmlhttp_obj;
  36.     }   //get content via GET
  37.  
  38.     function getcontent(url)
  39.     {
  40.         var xmlhttp_obj = ewd_xmlhttp();
  41.         document.getElementById(containerid).innerHTML = \'<img src="\' + loading_img + \'" />\' + loading_msg;
  42.         xmlhttp_obj.onreadystatechange=function()
  43.         {
  44.             loadpage(xmlhttp_obj);
  45.         }
  46.         xmlhttp_obj.open(\'GET\', url, true);
  47.         xmlhttp_obj.send(null);
  48.         alert(xmlHttp.responseText);
  49.         window.location.href = \'../../cases/'.$_REQUEST['id'].'/\';
  50.     }     
  51.  
  52.     function loadpage(xmlhttp_obj, containerid)
  53.     {
  54.         if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200 )
  55.         {
  56.             document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;
  57.         }
  58.     }
  59. //]]>
  60. </script>
  61. ...
  62. <select name="status" onchange="getcontent(\'../../sys_config/changeCaseStatus.php?id='.$cid.'&s=\'this.value\');"">'.getCaseStatusList().'</select>
changeCaseStatus.php
Expand|Select|Wrap|Line Numbers
  1. changeCaseStatus($_GET['id'],$_GET['status']);
Feb 6 '09 #1
9 1381
Atli
5,058 Expert 4TB
Hi.

Your function "loadpage" takes two parameters, the AJAX object and the ID of an element, which you use inside it to print the AJAX result.

On line #44, you call this function, but you don't pass it the second parameter, which means that your code doesn't have an element to put the AJAX response into.

And you also do this on line #41. You try to get an element using the variable "containerid", which I can't find anywhere.
Feb 7 '09 #2
acoder
16,027 Expert Mod 8TB
In addition to that, the URL only has a parameter "s" set, not "status" as expected in the PHP file.
Feb 7 '09 #3
ziycon
384 256MB
Ok, I'm trying this now with no luck:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function changeCaseStatus() {
  3.     var xmlHttp;
  4.     try {
  5.         // Firefox, Opera 8.0+, Safari
  6.         xmlHttp=new XMLHttpRequest();
  7.     }
  8.     catch (e) {
  9.         // Internet Explorer
  10.         try {
  11.             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  12.         }
  13.         catch (e) {
  14.             try {
  15.                 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  16.             }
  17.             catch (e) {
  18.                 alert("Your browser does not support AJAX!");
  19.                 return false;
  20.             }
  21.         }
  22.     }
  23.     function getcontent(url)
  24.     {
  25.         xmlHttp.onreadystatechange=function() {
  26.             if(xmlHttp.readyState==4) {
  27.                 xmlHttp.responseText;
  28.             }
  29.             window.location.href = \'../../cases/'.$_REQUEST['id'].'/\';
  30.             xmlHttp.open(\'GET\', url ,true);
  31.             xmlHttp.send(null);
  32.         }
  33.     }
  34. }
  35. </script>
  36. ...
  37. <select name="status" onchange="getcontent(\'../../sys_config/changeCaseStatus.php?id='.$cid.'&status=\'+this.value);">'.getCaseStatusList().'</select>
Expand|Select|Wrap|Line Numbers
  1. changeCaseStatus($_GET['id'],$_GET['status']);
Feb 7 '09 #4
acoder
16,027 Expert Mod 8TB
I'm not sure what you're trying to do. When you set window.location.href, the page will change to the new location. That will mean the Ajax call will be ignored.
Feb 7 '09 #5
ziycon
384 256MB
Bascily when the select box has been changed that it will call the page changeCaseStatus.php and pass the id and status vairables to it, then it will refresh back to the current page to show the change of status, does that explain it?
Feb 7 '09 #6
ziycon
384 256MB
The 'hi' alert is show up now and the page is refreshing but it wont retrieve the details on the changeCaseStatus.php page??
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function getcontent(url)
  3.     {
  4.     var xmlHttp;
  5.     try {
  6.         // Firefox, Opera 8.0+, Safari
  7.         xmlHttp=new XMLHttpRequest();
  8.     }
  9.     catch (e) {
  10.         // Internet Explorer
  11.         try {
  12.             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  13.         }
  14.         catch (e) {
  15.             try {
  16.                 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  17.             }
  18.             catch (e) {
  19.                 alert("Your browser does not support AJAX!");
  20.                 return false;
  21.             }
  22.         }
  23.     }
  24.  
  25.     alert("hi");
  26.     xmlHttp.onreadystatechange=function() {
  27.         if(xmlHttp.readyState==4) {
  28.             xmlHttp.responseText;
  29.         }
  30.     }
  31.     xmlHttp.open(\'GET\', url ,true);
  32.     xmlHttp.send(null);
  33.     window.location.href = \'../../cases/'.$_REQUEST['id'].'/\';
  34. }
  35. </script>
  36. ...
  37. <select name="status" onchange="getcontent(\'../../sys_config/changeCaseStatus.php?id='.$cid.'&status=\'+this.value);">'.getCaseStatusList().'</select>
changeCaseStatus.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include_once('../../database.php');
  4. include_once('../../sql_query.php');
  5.  
  6. dbConnect();
  7.  
  8. changeCaseStatus($_GET['id'],$_GET['status']);
  9.  
  10. closeConnect();
  11. ?>
Feb 7 '09 #7
ziycon
384 256MB
Okay, got it working fine on my local machine but when i upload it to the next it doesn't work, any ideas?
Feb 7 '09 #8
acoder
16,027 Expert Mod 8TB
The whole purpose of Ajax is to avoid reloading the page. If that's not a requirement, then there's no need to use Ajax.
Feb 9 '09 #9
ziycon
384 256MB
Yup, i know what i did wrong now! :D Thanks.
Feb 9 '09 #10

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

Similar topics

11
by: Yarco | last post by:
I want to use "Ajax" to create my web for hobby. But i don't know whether "Ajax" is mature... And what about with php? Someone have experience on it? ....
4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
12
by: wangzx | last post by:
I am the author of easyajax.sourceforge.net, and I have a problem on Firefox 1.5, I post the problem here and hopes somebody help me. The test page can be:...
0
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
0
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
0
by: preeti13 | last post by:
i have a two tables employeenominations and reason if someone storing a data first time it will store into the employeenominations table if name is already exist it will store into the reason table...
1
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...
1
by: prarthanaraut | last post by:
Hi, I am getting Browser problerm while using AJAX in classic ASP code. I want to execute some asp code when user clicks on checkboxes on one page without refreshing the page. I have...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
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...
0
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...

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.