By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,517 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,517 IT Pros & Developers. It's quick & easy.

AJAX: How to pass file names to a php script?

100+
P: 118
Hi all,

I have a photography page on my website, I have pictures on the page (obviously) but the file names are stored and loaded in Javascript, in an array.

Expand|Select|Wrap|Line Numbers
  1. var pic = new Array("./images/under1[1].png","./images/anemon.png","./images/arrow.png", "./images/babymoray.png","./images/grouper.png","./images/meridian.png", "./images/grouper1.png","./images/moray.png", "./images/morayeel.png", "./images/toitle.png", "./images/triggerfish.png", "./images/wreck.png", "./images/end.png");
  2. var thisPic = 0;
  3. function doPrevious() {
  4.     if (document.images && thisPic > 0) {
  5.         thisPic--
  6.         document.baroque.src=pic[thisPic]
  7.     }
  8. }
  9.  
  10. function doNext() {
  11.     if (document.images && thisPic < 12) {
  12.         thisPic++
  13.         document.baroque.src=pic[thisPic]
  14.     }
  15. }
  16.  
Expand|Select|Wrap|Line Numbers
  1. <img style="border-color:#000000;" name="baroque" src="./images/under1[1].png" usemap="#thismap"><map id="thismap" name="thismap"> <area shape="rect" coords="40,15,85,25" href="javascript:doPrevious()" alt="previous" target="_parent"><area shape="rect" coords="460,15,490,25" href="javascript:doNext()" alt="next" target="_parent"><area shape="rect" coords="295,195,320,205" href="javascript:history.back(-1)" alt="back" target="_parent"></map>

I have set up a MySQL database to hold: the filename, username, email address and the comment. So when a user posts a comment it posts it to the database then pulls it from the database and enters it into a div on the page. Where people can read it.

The only problem is that the file names are stored using Javascript, so when the 'Next' button (doNext() function) is pressed/called the filename changes. But to load the comments I need to use PHP.

(Hope that made sense so far) Is there a way to pass the filenames, from the javascript to a php script in order to load the relevant comments?

Is this possible with ajax? Or, if not, can anyone suggest another way of storing the comments, perhaps XML?

Thanks,

Sam
Nov 11 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
If I've understood you correctly, yes, it should be possible with Ajax. Pass the filename to the PHP script. The server-side script returns the comments in responseText or responseXML and you can either use it directly or parse it to get the comments. See an example.
Nov 12 '07 #2

Post your reply

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