| | |
ajax problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2005
Posts: 149
Reputation:
Solved Threads: 0
Hi,
I am trying to implement the following ajax code:
I have called the showdetail function a link click and passed it's id. The problem is that the dv is not updated data. Is there any problem with the link?
Thanks for your time.
I am trying to implement the following ajax code:
PHP Syntax (Toggle Plain Text)
function create() { obj_t = new XMLHttpRequest(); if(obj_t == null) { alert("Your broweser does not support it"); } } function data() { if(obj_t!=null) { if(obj_t.readyState == 4) { var dv = document.getElementById('tdetail'); dv.innerHTML = obj_t.responseText; } } } function createRequest(id) { obj_t.open("GET","functions/travellerdetail.php?tid="+id,true); obj_t.onreadystatechange = data; obj_t.send(null); } function showdetail(tid) { create(); createRequest(tid); }
I have called the showdetail function a link click and passed it's id. The problem is that the dv is not updated data. Is there any problem with the link?
Thanks for your time.
This should be in the JavaScript forum but from looking at your code quickly it seems ok but you need to make sure the browser your using supports creating your XMLHttpRequest object like you do. The following code is taken from a project of mine which I know works feel free to try it out and see if its working in place of your code.
javascript Syntax (Toggle Plain Text)
var createXmlHttpRequest = function() { var x; try { x = new XMLHttpRequest(); } catch(ex) { try { x = new ActiveXObject("Msxml2.XMLHTTP"); } catch(ex2) { try { x = new ActiveXObject("Microsoft.XMLHTTP"); } catch(ex3) { x = false; } } } if(x) { return x; } else { return false; } }; var createUniqueUrl = function(url) { return url + (url.indexOf('?') !== -1 ? '' : '?') + '&$=' + new Date().getTime(); }; var ajax = function(url, id) { var xmlHttp = createXmlHttpRequest(); if(xmlHttp) { xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState === 4) { var data = xmlHttp.responseText; } }; url = createUniqueUrl(url + '?id=' + id); xmlHttp.open('GET', url, true); xmlHttp.send(null); } };
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
you have alerted the 'obj_t.responseText' value and it definately is returning text ? Also do you have an element in the page with ID 'tdetail'. If so can you post your pages HTML as there may be a problem elsewhere
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
Join Date: Apr 2005
Posts: 149
Reputation:
Solved Threads: 0
Thanks for your time. I am posting the whole code, please guide about the mistakes.
php Syntax (Toggle Plain Text)
<? include "functions/mysql.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Find Travellers</title> <link rel="stylesheet" type="text/css" href="stylesheet/style.css"> <script> var obj_t; function create() { obj_t = new XMLHttpRequest(); if(obj_t == null) { alert("Your broweser does not support it"); } } function data() { if(obj_t!= null) { if(obj_t.readyState == 4) { var dv = document.getElementById('tdetail'); dv.innerHTML = obj_t.responseText; } } } function createRequest(id) { obj_t.open("GET", "functions/travellerdetail.php?tid="+id , true); obj_t.onreadystatechange = data; obj_t.send(null); } function showdetail(tid) { create(); createRequest(tid); } </script> </head> <body> <table> <tr><td> <?$Q = mysql_query("select * from travellers where t_type = 'air'");?> <div id="byair"> <? while($R = mysql_fetch_array($Q)) { ?> <br /> <a href="" class="tlink" onclick="showdetail(<? echo $R["t_id"]; ?>)" id="<? echo $R["t_id"]; ?>" name="<? echo $R["t_name"]; ?>"> <? echo $R["t_name"]; ?> </a> <? } ?> </div></td></tr> <tr><td><div id="tdetail"></div></td></tr> </table>
Last edited by marjan_m; Apr 19th, 2009 at 2:54 am.
First of all if the document is (X)Html then your link tag needs to be closed.
should be
Secondly the script tag REQUIRES you to specify its type.
should be
You also need a closing </body> and </html> tag at the end of the document. Ive taken your script and reformatted it, try the following.
•
•
•
•
html Syntax (Toggle Plain Text)
<link rel="stylesheet" type="text/css" href="stylesheet/style.css">
html Syntax (Toggle Plain Text)
<link rel="stylesheet" type="text/css" href="stylesheet/style.css" />
Secondly the script tag REQUIRES you to specify its type.
should be
html Syntax (Toggle Plain Text)
<script type="text/javascript">
You also need a closing </body> and </html> tag at the end of the document. Ive taken your script and reformatted it, try the following.
php Syntax (Toggle Plain Text)
<? include "functions/mysql.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Find Travellers</title> <link rel="stylesheet" type="text/css" href="stylesheet/style.css" /> <script language="javascript" type="text/javascript"> function createXmlHttpRequest() { var x; try { x = new XMLHttpRequest(); } catch(ex) { try { x = new ActiveXObject("Msxml2.XMLHTTP"); } catch(ex2) { try { x = new ActiveXObject("Microsoft.XMLHTTP"); } catch(ex3) { x = false; } } } if(x) { return x; } else { return false; } } function showdetail(tid) { var xmlHttp = createXmlHttpRequest(); if(xmlHttp) { xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState === 4) { var data = xmlHttp.responseText; var dv = document.getElementById('tdetail'); dv.innerHTML = data; } }; xmlHttp.open('GET', 'functions/travellerdetail.php?tid=' + id, true); xmlHttp.send(null); } return false; } </script> </head> <body> <table> <tr> <td> <?$Q = mysql_query("select * from travellers where t_type = 'air'");?> <div id="byair"> <? while($R = mysql_fetch_array($Q)) { ?> <br /> <a href="#" class="tlink" onclick="return showdetail(<? echo $R["t_id"]; ?>)" id="<? echo $R["t_id"]; ?>" name="<? echo $R["t_name"]; ?>"><? echo $R["t_name"]; ?></a> <? } ?> </div> </td> </tr> <tr> <td> <div id="tdetail"></div> </td> </tr> </table> </body> </html>
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
so does it still do this with my example ?
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
![]() |
Similar Threads
- AJAX problem (JavaScript / DHTML / AJAX)
- Frustrating Firefox Problem while making AJAX request on an anchor (JavaScript / DHTML / AJAX)
- Radio Button - AJAX - Problem with Passing Value (JavaScript / DHTML / AJAX)
- Problem with page link. (JavaScript / DHTML / AJAX)
- multiple radiobutton values ajax problem (JavaScript / DHTML / AJAX)
- AJAX Question (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: dynamic array and dymanic variables
- Next Thread: PHP-MySQL question
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alerts apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop overwrite parse paypal pdf php problem query radio random recursion redirect regex remote script search securephp server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube





