JQuery Rules!

Lately I've been working on learning not only JQuery but also more on CSS, Javascript and more PHP.  We're using API's to handle any sql calls. 

An experimental project involved transfer courses and which schools offer which courses that have PSU equivalents was used to not only familiarize myself with jquery but also understand all the other components that are needed (or just desired) to have in the application. 

Then I moved onto a program which allows a user (via an oracle directory object) to be able to upload their feeds without connecting to unix.  JQuery handled this beautifully sans some obstacles such as quotes begin uploaded getting in the way etc.  I would like to share bits of this technique. 

Things that need to happen are:

  • Make sure all is secure,  I use Yale CAS so the user not only needs a portal account, but they also need to be included in the authorization listing. 
  • Set up the mechanism to get the file to be uploaded. 
  • Give the filename a title which is passed as a parameter
  • Allow the user to view the contents before uploading.  From the time the file is picked up, it is encoded. 
  • Then when the user clicks on the upload button, it automatically goes to the directory for pickup later on. 

I can not show all the code, but can show the obstacles that got in my way while working on this.  First issue was passing an array successfully.  We ended up flattening it out like this:

  <!-- BEGIN: items -->
   <input type="hidden" name="itemarray{items.nbr}" class="itemarray" value="{items.record}" />
  <!-- END: items -->
Then this value is picked up by my behavior.js  file containing javascript and jquery where the next php app picks up these values and moves the data along    [segment from behavior.js]:

  var statement='variable_list.'+$(this).attr('name')+'="'+$(this).val()+'"';

What that basically did was, after I assigned a class called itemarray (in the template),  jquery can now search for the class and pick up the attributes and values.  If you want to put it back into an array afterwards, just assign the values in a loop back into it. 

Issue #2:  This one had me stumped at first, but although it picked up the file I was transferring correctly, when I tried to upload a comma quote delimited file - the items in behavior.js didn't know what to do with the quotes!  Finally I found that if you do a urlencode first when sending the values and then urldecode the values when you wish to view the results, it works great.  If you do nothing and there are quotes in the file, nothing will upload and the process will fail. 

So, the process is now working.  Thanks to Matt Batchelder for helping me with some of this and getting me started with jquery!  Hope you find some of this useful. 

Jquery continuing....

Well, still having fun with Jquery.  I'm curious though if there are any experts out there that have used Jquery in an application that involves downloading and uploading files?  We've been experimenting with it and found that uploading and downloading involves more than I thought.   The biggest hurdle with this is associative arrays.  As soon as I can figure out the best way to handle this, will post.  If you know easy ways to do this please do post!  Thanks.