/* Internet Addiction */

Learn it, Live it, Love it.

Archive for June 2009

Google VS PHP

without comments

Here is the recent article Google published for Web optimisation technique for PHP. It got bad PHP community slap back especially from the Sitepoint.com and Google group forum. It is quiet interesting to see how beginner PHP will actually fall in the trap which recomemded so of the tips from the articles.

Written by Charles Ling

27 June, 2009 at 9:14 PM

Posted in PHP

Tagged with

JQuery get $.getJSON data

with one comment

Imagine you have server side data return to your Javascript client side.

   1:  var groupid = null;
   2:  
   3:  $.getJSON(url, data,
   4:      function(result){
   5:  
   6:       groupid = result.groupid;
   7:       //do whatehever you like here
   8:  
   9:      // you wanted to return the data that you have been parsed or assign
  10:      }
  11:  );
  12:  
  13:  alert(groupid ); //error : will return null

So instead of that, we need to use delegate or callback function that JQuery have provided to us. Remember the $.fn. thing.

Now let see how we can use the delegate function to return us the data:

   1:  $.getJSON(path + "?request=url.here",
   2:  function (data)
   3:  {
   4:     var selectOption = '';
   5:  
   6:     //do what ever you like with the json data
   7:     selectOption =  selectOption + "testing" + data; //example only
   8:     $.fn.delegateJSONResult(selectOption );
   9:  });
  10:  
  11:  $.fn.delegateJSONResult = function(data) {
  12:    alert(data);
  13:  }

Written by Charles Ling

27 June, 2009 at 6:42 PM

Posted in Javascript, jQuery

Tagged with ,