VJ’s Warez

Steve Marx has created a PHP library for the Microsoft Ajax 1.0 release that uses the JavaScript piece in PHP land.

The Microsoft AJAX Library is a pure-JavaScript library that’s used by ASP.NET AJAX but is also available as a separate download. Because it’s pure JavaScript, it’s not tied to ASP.NET on the backend. PHP for MS AJAX is code to help you make use of the Microsoft AJAX Library from PHP applications. With this first Alpha release, it simply supports exposing PHP classes as AJAX-enabled web services, just as in ASP.NET applications. In fact, the generated proxies are identical to what you get from ASP.NET, meaning you can have full interoperability.

Hello World

The service on the backend so to speak:

  1. <?php
  2. require_once ‘../../dist/MSAjaxService.php’;
  3. class HelloService extends MSAjaxService
  4. {
  5. function SayHello($name)
  6. {
  7. return “Hello, “ . $name . “!”;
  8. }
  9. }
  10. $h = new HelloService();
  11. $h->ProcessRequest();

And the front end that will talk to it:

  1. <title>Hello, World!</title>
  2. <script type=“text/javascript” src=“../../MicrosoftAjaxLibrary/MicrosoftAjax.js”></script>
  3. <script type=“text/javascript” src=“HelloService.php/js”></script>
  4. </head>
  5. Name: <input id=“name” type=“text” />
  6. <input type=“button” value=“Say Hello” onclick=“button_click(); return false;” />
  7. <br />
  8. Response from server: <span id=“response”></span>
  9. </body>
  10. <script type=“text/javascript”>
  11. function button_click() {
  12. HelloService.SayHello($get(‘name’).value, function (result) {
  13. $get(‘response’).innerHTML = result;
  14. });
  15. }
  16. </script>
  17. </html>

Sam Ruby has that way about him that sees things very clearly. He just took a peak at jQuery for the first time and was able to really put into words what I think jQuery enthusiasts like about the library:

The notable thing about this is that despite all of the asynchronous events taking place, the code is sequential (nested, but sequential), and that the JSON results of the AJAX call is immediately available to the function that is invoked when the selection changes.

This is based on the following code that he wrote:

  1. $(“#archive”).click(function() {
  2. $.getJSON(‘unscanned.cgi’, {}, function(unscanned) {
  3. // replace realname input field with a selection list
  4. var select = $(‘<select name=”realname” id=”realname”/>’)[0];
  5. for (var i=0; i<unscanned .length; i++) {
  6. select.options[i] = new Option(unscanned[i][1], i);
  7. }
  8. $(‘#realname’).before(select).remove();
  9. $(“#archive”).attr(“disabled”,“disabled”);
  10. // process selection
  11. $(‘#realname’).focus().change(function() {
  12. var icla = unscanned[$(“#realname option:selected”).val()];
  13. $(“#realname”).before(‘<input type=”text” ‘ +
  14. ‘id=”realname” name=”realname”/>’).remove();
  15. $(“#realname”).val(icla[1]);
  16. $(“#pubname”).val(icla[2]);
  17. $(“#email”).val(icla[3]);
  18. $(“#replaces”).val(icla[0] + ‘:’ + icla[3]);
  19. $(“#filename”).val().focus();
  20. $(“#archive”).removeAttr(“disabled”);
  21. });
  22. });
  23. return false;
  24. });

Those that love jQuery, love the API.

John himself had an example in the comments:

  1. $(‘:radio[name=is_user]’)
  2. .change(function(){ $(‘.depends-isuser’)[ this.value == 1 ? ‘show’ : ‘hide’ ](); })
  3. .change();

jQuery 1.3 beta 1 has been released with John and the team asking for testing help.

This is a big release as a lot has been changed:

  • Sizzle has been integrated
  • No more browser testing: For example, no more if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { which is replaced with if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
  • Live event delegration: Reglib’s claim to fame was how event delegation was “live” meaning that if you added elements later on, they would also fall into the same delegations. With $("#foo > div").live("click", someFn); you get the same in jQuery
  • $(this).closest("div");: Returns this or closest ancestor that matches selector
  • .offset() rewrite – significantly faster, uses no browser sniffing.
  • .hide()/.show() rewrite – 50% – 200% faster.
  • .append/prepend/before/after rewrite – 10-15x faster.

I like getting data from the web and I love JSON – as it is easy to use. The issue is that not many things on the web come as JSON from the get-go. Hence we need converters. You can use cURL and beautiful soup or roll your own hell of regular expressions. Alternatively you can use Yahoo Pipes to build your converter. Pipes is the bomb but a lot of people complained that there is no version control and that you need to use the very graphical interface to get to your data (which was the point of Pipes but let’s not go there).

AlasRejoice for there is a solution now available and it is called YQL. YQL is a SQL-style language to get information from all kind of web services, and – using oAuth – even Yahoo’s social graph. There is a test console available for you to get to grips with all the information it gives you access to (which is a lot!):

The YQL console

Here comes the kicker though: for all the open services that don’t need authentication you can use these YQL statements as a REST API with JSON output and an optional callback function for JSON-P by adding it to http://query.yahooapis.com/v1/public/yql?. For example to get the latest three headlines from Ajaxian’s RSS feed as JSON and wrap it in a function called leechajaxian do the following: Read the rest of this entry »

Today we are fortunate to have a guest post by Patrick Lightbody, most recently of BrowserMob fame (and previously Selenium work, OpenQA, WebWork, and more). Let’s listen in to him talk to us about load testing, and let him know your thoughts in the comments below:

I’ve been developing and testing complex web apps for a long time. I was the co-creator of WebWork (now Struts 2.0) and an early champion of DWR, writing one of the first AJAX form validation frameworks for Java web apps. But over the years, I noticed that as our web technologies and techniques got more sophisticated, our testing techniques were not keeping up.

That was why I founded OpenQA and helped grow Selenium to the popular testing tool that it is today. Selenium helps with functional testing of complex AJAX apps, but there isn’t an equivalent for load testing, which is why I started BrowserMob, a new type of load testing service. Read the rest of this entry »

At a New Years Eve party, a friend help up a drink and toasted to his company deciding to discontinue direct support of IE 6 in 2009, and letting users know that the site may work better with IE 7 or another latest browser.

Then, Asa Dotzer puts up a chart of the IE 6 numbers:

Read the rest of this entry »

So, another “PHP sucks” post, this time from Jeff Atwood. He actually ends up even kind of praising PHP, surprised by its success. I have a couple of thoughts on that topic too.

First, people really need to stop reading something on PHP written somewhere in 2005 (probably about experiences that happened in 2001) and apply it to PHP as it is now, without even checking around for current trends. It’s as if people would dig up books from middle ages saying that there are only seven metals in existence or debating about phlogiston, and would use it speaking about the modern chemistry. Come on! Read the rest of this entry »

VJ’s Warez