| | |
csv file, ajax, php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 0
i'm parsing a csv file with ajax and php, although i think i did everything right, nothing happens when i click on the link.
here is the code:
can anyone please tell me what is wrong with this code?
thanks...
here is the code:
PHP Syntax (Toggle Plain Text)
here is the html: <div id="brandContainer"> <ul id="brandNav"> <li class="categorypage" id="face"><a href="javascript:showCD('a','brandPage')">A</a></li> </ul> <div id="brandPage"></div> </div> here is the ajax/javascript: var xmlhttp function showCD(str, div) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="getbrands.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged(div); xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged(div) { if (xmlhttp.readyState==4) { document.getElementById(div).innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } and here is the php(getbrands.php): <?php $q=$_GET["q"]; $handle = fopen("http://www.totalbeauty.com/resource/lists", "r"); while (($data = fgetcsv($handle, ";;")) !== FALSE) { $brands= $data[0]; } $brand = explode(",", $brands); for ($i=0; $i<=count($brand); $i++){ $a=strtolower($brand[$i]); $display = "<ul>"; if ($q = $a[0]){ $display .= "<li>'".$a."'</li>"; } $display .="</ul>"; echo $display; } ?>
can anyone please tell me what is wrong with this code?
thanks...
If you get an error make sure it is not an access denied. An access denied is pretty common if your on a windows server. Because your requesting xmlhttp.open("GET",url,true); and windows is funny about those things.
Try this:
here is the ajax/javascript
here is the html
and here is the php(getbrands.php)
Try this:
here is the ajax/javascript
PHP Syntax (Toggle Plain Text)
var xmlhttp; function showCD(str, div) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="getbrands.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged(div) { if (xmlhttp.readyState==4) { document.getElementById(div).innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; }
here is the html
PHP Syntax (Toggle Plain Text)
<div id="brandContainer"> <ul id="brandNav"> <li class="categorypage" id="face"><a href="javascript:showCD ('a','brandPage')">A</a></li> </ul> <div id="brandPage"></div> </div>
and here is the php(getbrands.php)
PHP Syntax (Toggle Plain Text)
<?php $q=$_GET["q"]; $handle = fopen("http://www.totalbeauty.com/resource/lists", "r"); while (($data = fgetcsv($handle, ";;")) !== FALSE) { $brands= $data[0]; } $brand = explode(",", $brands); for ($i=0; $i<=count($brand); $i++){ $a=strtolower($brand[$i]); $display = "<ul>"; if ($q = $a[0]){ $display .= "<li>'".$a."'</li>"; } $display .="</ul>"; echo $display; } ?>
Last edited by Banderson; Jul 22nd, 2009 at 5:44 am. Reason: corrected error
![]() |
Similar Threads
- insert csv file into mysql through php (PHP)
- Create a link in a table read from a CSV file and pass a variable (PHP)
- how to delete extra commas on csv file with php (PHP)
- AJAX & PHP Developer ( Full Time ) (Web Development Job Offers)
- How to read data from csv file in an array and parse (C++)
- parsing csv file (PHP)
Other Threads in the PHP Forum
- Previous Thread: show the file icon
- Next Thread: Search for an exact match
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search secure server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





