AJAX Hello World with HTML_AJAX

This is a continuation of my AJAX Hello World series, in my earlier posts I covered sajax and JPSpan. In this article i’ll cover how to get a basic AJAX appliction up and running with HTML_AJAX. If you haven’t figured it out yet im one of the author’s of HTML_AJAX. The application in question is the same simple app as the other examples, it has an input box for adding random strings and an button to add a random one to a div.

When your using HTML_AJAX you have more choices then with either JPSpan or sajax. But to keeps things simple were going to use a setup similar to how we used JPSpan, an external server page that generates a JavaScript proxy which is included by our html page that does the actual action. HTML_AJAX could also be used sajax style with the proxy and server code generated inline, but I don’t recommend this usage since it remove your ability to cache the generated JavaScript.

Installing HTML_AJAX

This is nice and simple its simply:
pear install HTML_AJAX-alpha
If you don’t have pear setup on your server just follow the installation instructions in the PEAR Manual.

Setting up the Server Component

An HTML_AJAX server page is generally very simple, it creates an HTML_AJAX_Server instance, registers all the classes you want exported and handles incoming requests. The incoming requests can be three different types:

  • Client library request: query string includes ?client=all (can also be each of the seperate component parts)
  • Generated stub requests: query strings includes ?stub=classname (all keyword can also be used)
  • AJAX Requests: query string includes ?c=classname&m=methodname

Client and Stub requests can be combined into the same one, but remember there is a tradeoff when doing that. You’ll have less roundtrips to the server but generated stubs are more likely to change so they can hurt your cacheability. You also want to be careful about using stub=all since the stub for 10 different classes can be quite large. The next release will also allow for combining multiple classes in a stub request by seperating them with a comma like so: stub=test,test2. Finally a note on class names, in php4 they will be lower case since thats what PHP returns, if you would like to have case or need to guarantee php4/5 compatability you’ll want to use some optional paramaters to registerClass, the first is the name to register the class in JavaScript as, the second is an array of methods to export.
A basic server is shown below.

<?php

session_start();

require_once 'HTML/AJAX/Server.php';
require_once 'HelloWorld.class.php';

$server = new HTML_AJAX_Server();

$hello = new HelloWorld();
$server->registerClass($hello);

$server->handleRequest();

?>

A server like this works fine for small scale projects, but it might not be a good choice for something larger since you could be creating 20 class instances just to serve a request on one of them. Any custom setup also has to be done for each class. HTML_AJAX provides a way to manage this by extending the server class and adding an init method for each class. A server that does this for the same HelloWorld class is shown below.

<?php

session_start();

require_once 'HTML/AJAX/Server.php';

class AutoServer extends HTML_AJAX_Server {
        // this flag must be set for your init methods to be used
        var $initMethods = true;

        // init method for my hello world class
        function initHelloWorld() {
                require_once 'HelloWorld.class.php';
                $hello = new HelloWorld();
                $this->registerClass($hello);
        }

}

$server = new AutoServer();
$server->handleRequest();

?>


PHP Application Code

In the server examples above you’ll notice were including a Hello World class. This hasn’t changed from the JPSpan example. The only thing of note is that makes heavy use of session, many AJAX apps will share this same heavy use, so make sure your server setups can handle that.

<?php

// our hello world class
class HelloWorld {

        function HelloWorld() {
                if (!isset($_SESSION['strings'])) {
                        $_SESSION['strings'] = array('Hello','World','Hello World');
                }
        }

        function addString($string) {
                $_SESSION['strings'][] = $string;
                return $this->stringCount();
        }

        function randomString() {
                $index = rand(0,count($_SESSION['strings'])-1);
                return $_SESSION['strings'][$index];
        }

        function stringCount() {
                return count($_SESSION['strings']);
        }
}

?>

The HTML that ties it all together

To finish up our app we need to create the HTML that ties it all together. This is going to have two main parts, the main JavaScript logic, callback function for our async requests and a fake form. The call the form fake, because there is no form tags, were just powering everything off onclick event handlers on buttons. At some point in the future HTML_AJAX will support taking a normal form and magically turning it into an AJAX one but for now that thought is just in my head.

The page starts with normal HTML boiler plate and an include of our client library and the stub hello world class. They are done all in a single class since that makes sense for this example, if I had 10 classes it wouldn’t.

Next we build the callback hash, it has a method for each method in PHP, they will be called from the results from an async AJAX call. In this example each call back is really simple it either updates an element using innerHTML or appends to one. You could also use a normal JavaScript class instead of a hash, but thats only useful if you need multiple instances.

The next step is to create an instance of our helloworld class and create a helper function. When we create an instance of our proxy class we pass in our callback, if we didn’t the instance would work in a sync manner, which can be useful, but in this case would make for a choppy ui. The helper function do_addString isn’t anything exciting, it just clears out the textbox after we’ve submited its current value.

Finally we have the html body of the page, it contains our buttons with onclick event handlers that call remote functions. It also contains our output divs.

Trying out the sample

If you got this far you’ll want to try out the Hello World app were building. If you compare it against the JPSpan or sajax version you won’t notice many differences. The only visual one that should show up is loading notice in the top right corner. Since providing user feedback is such an important part of making a usable AJAX application HTML_AJAX includes this basic loading symbol out of the box. If you just want to customize its looks you just need to create an element with the id of HTML_AJAX_LOADING. Its shown by setting its display style to block, and hidden by setting display to none everything else is left up to you so make sure to take care of any positioning and setting its display to none so its hidden by default. If you want to do somthing more complex you can override HTML_AJAX.onOpen and HTML_AJAX.onLoad check out the current methods to see hows its done.

Finally you might notice some JavaScript errors if you try to make a lot of quick requests, like JPSpan HTML_AJAX only provides for one concurrent request at a time. This will change in the future giving you a number of different options but for now you can either keep those from happening at the application level, or just add a error handling function to HTML_AJAX.onError and ignore the call in progress ones.

You can also download the project and try it out on your own server, its available as a tar.gz or a zip.

Where to go from here

Now that you’ve had a look at HTML_AJAX you might be wondering how to learn more about it. For the moment your options are pretty limited. You can check out the examples dir (in the docs dir in pear or online) or you can ask questions on this post. You might also find the source to be useful, for now the newest version lives on my svn server.

Feed back is appreciated as I’ll use that to decide what features to add to HTML_AJAX and what to fully document next, feel free to post comments or trackbacks even if you have a lot to say.

Update:
This example won’t work correctly in PHP5 since the methods will be exported with CASE, take a look at the generated JavaScript if you don’t understand what i mean (auto_server.php?clalss=helloworld). See Comment #40 for your options to fix things.

103 Responses to “AJAX Hello World with HTML_AJAX”

  1. 1

    New ‘AJAX’ Tutorial, ala Joshua Eichorn

    I just got done reading through this post by Joshua Eichorn. It is a nice little tutorial on how to set up and create a small little app with HTML_AJAX. Unfortunately for me I just started using JPSpan and have finally gotten use to all of it’s quirks…

  2. 2

    [...] ¿Qué mejor forma de celebrar la aparición del paquete de PEAR HTML_AJAX que con un tutorial sobre HTML_AJAX? El autor tiene otros pequeños tutoriales sobre otras librerías, lo que nos permitiría buscar la que mejor se adapte a nuestras necesidades (todas en PHP). [...]

  3. 3

    Hello
    I have installed pear on the server.
    Then i have installed HTML_AJAX.
    How do i call ajax in my .php pages ?

  4. 4

    The AJAX calls come from the Javascript side to your php backend logic, im not quite sure what your asking. Check out the examples (in the pear doc dir) to get a better idea of how the basic setup works.

  5. 5

    Where is the “see a working version here” link, Joshua?? I know you can do it…

  6. 6

    http://blog.joshuaeichorn.com/examples/HTML_AJAX-HelloWorld/

  7. 7

    I am having trouble getting the example to work. The HTML_AJAX-0.2.1 is installed, but when I attempt to load up the example, the string count is not displayed and entering a string is not possible. The error seems to stem from the initial The error I receive is: object doesn’t support this property or method. Any help would be appreciated. I would love to get this working!

  8. 8

    jeremy what browser are you using

  9. 9

    Same results in both FireFox and Internet Explorer…

  10. 10

    On reading post 7 I realized the html was stripped. In Internet Explorer I viewed the javascript error message which pointed to line 31 which is the onload method.

  11. 11

    I guess its a problem with the install, everything looks fine on my test copy. Do you have a URL i can view the error at. Also if you want quicker turn around on the debugging feel free to email me (josh@bluga.net) and i’ll my instant messenger info.

  12. 12
    Kazuyuki Ohgushi Said:

    Jeremy,

    The same problem would occur on me. I installed HTML_AJAX-0.2.1 on PHP5.0.4.

  13. 13

    I installed HTML_AJAX mannually.

    http://pear.php.net/manual/en/installation.manually.php

    However, sample source doesn’t work …

    my uploaded example URL is following:

    http://gushitaro.net/HTML_AJAX-HelloWorld/

  14. 14

    Ok the problem with the sample code and PHP5 is case. Right now HTML_AJAX uses the case your code is written in when exporting in php5. But it always uses lowercase in php4 since the upper case version isn’t available.

    I have a todo item for adding a compatability mode that also lowercases functions in php4. But for now if you need to be compatible between php 4 and 5, you’ll need to pass an array of method to export to registerClass.

    -josh

  15. 15

    Sorry.
    My server’s PHP Version is 4.3.10
    http://gushitaro.net/HTML_AJAX-HelloWorld/

    Do you have some idea for correcting this error ?

  16. 16

    Kazuyhuki:

    If you don’t install things using pear you need to set the location of the javascript libraries.

    $server->clientJsLocation = “path/to/jslibs”;

  17. 17

    Thanks!! Joshua

    http://gushitaro.net/HTML_AJAX-HelloWorld/

    My uploaded sample code does work.

    I wannna try to contribute this community.

  18. 18

    Hi Joshua,

    the jpspan site is still down since the wiki broke down. But I was wondering, is HTML_AJAX supposed to be the successor to JPSpan? Or are they really 2 different projects? There doesn’t seem to be a lot of activity on jpspan, but there is on html_ajax. So it’s probably better to go with html_ajax?

  19. 19

    Ivo: HTML_AJAX is a seperate project from JPSpan but its meant to be an easy upgrade path since thats how im using it.

  20. 20

    This looks great. I’m anxious to start working with it, however, I’m trying to use HTML_AJAX version 0.3.0 without pear and am having trouble figuring out what I need to change to get it to work.

    Which files need to be edited? for example there are a number of includes for files in HTML/AJAX however I don’t have an HTML directory. I’ve made a test directory…
    /docRoot/test/AJAX.php
    /docRoot/test/AJAX/
    /docRoot/test/examples/
    /docRoot/test/js/

    given only this and the standard files within the supplied directories how would I make the examples work?

  21. 21

    Todd:
    Well first thing first, the easiest thing to do is to use HTML_AJAX with pear. At some point i’ll start building tarballs that are meant to be used without the pear installer but im not there yet process wise.

    That being said if you extract HTML_AJAX and then rename the root directory to HTML and put it in your include_path things should work.

    so in your case the test directory becomes HTML and everything should work.

  22. 22

    I’ll definately look into PEAR. At the moment that seems like a larger learning process and I think I’m just a simple error away from getting HTML_AJAX to work.

    Following your advice I’ve renamed “test” to “HTML” However I stil get the same errors:

    http://localhost/HTML/examples/queue_usage.php
    yeilds — ReferenceError – Can’t find variable: livesearch

    I’ve also created a /docRoot/HTML/helloWorld with the above code to the same end. It seems to me that the “helloWorld” and “examples” dirs should be at the same level as “HTML” given that “server.php” tries to load “HTML/AJAX/Server.php” unfortunately that returns the same ReferenceError

    Thanks for your help.

  23. 23

    There is a real error hiding there yet.

    If you goto http://localhost/HTML/examples/auto_server.php?stub=livesearch

    You can see the php error thats causing your problems.

    Also installing pear is quite easy: http://pear.php.net/manual/en/installation.getting.php

  24. 24

    I’m sorry, even setting “error_reporting(2047)” I cannot find a php error. I’ll keep looking.

  25. 25

    Your local server should be generating the same stub as the one on my test server.

    Your Server
    http://localhost/HTML/examples/auto_server.php?stub=livesearch

    Test Server
    http://bluga.net/projects/HTML_AJAX/examples/auto_server.php?stub=livesearch

    If the stubs are different in anyway you have a problem.

  26. 26

    Of course you’re correct. My local server just returns a blank page. I’m not sure why because I haven’t altered that file.

  27. 27

    The file is generated, im sure your hitting an error yet, maybe its getting logged instead of being displayed.

  28. 28

    Briliant!!

    Tailing /var/log/httpd/error_log helped me debug the process. Ultimately in place of your “HTML” directory includes I placed a full path to the directory. I had to do it for all the files, and I missed a few the first time I tried. Fantastic work though. I’m going to try and embed it into the work I’m doing. I’ll let you know when I’m done so you can see YOUR results.

    Thanks again.

  29. 29

    I see on my verison and on your live example that when I hit “How Random String” that the red loading box appears, but it dies there… just sits… However, Kazuyuki Ohgushi’s link does work… just curious what was different…

  30. 30

    Ya this si the error I can see…
    Notice: Could find an init method for class: livesearch in /usr/share/pear/HTML/AJAX/Server.php on line 493

  31. 31

    Logan: If you send a message to the mailing list i can help you debug.

    Could be anything from php5 issues to a messed up install, to something we broke in a release.

    http://lists.bluga.net/mailman/listinfo/html_ajax-devel
    html_ajax-devel@lists.bluga.net

  32. 32

    You are the man! Wow! Blimey! This absolutely rocks! What I really love is that you used JSON to move data structures between PHP and JavaScript so I can move real data around, not just chunks of HTML. When I’ve finished the AJAX version of my site, I’ll be sure to offer you a free account to say thank you.

  33. 33

    your helloworld example didn’t work on my server until I changed the function names:
    addstring to addString
    stringcount to stringCount
    ..

  34. 34

    Laubi:
    This is caused by the fact that php5 supports case in function and class names and php4 doesn’t.

    If you want portability you can register the names manually instead of automatically.

    $this->registerClass($hello,’HelloWorld’,array(‘addString’,'randomString’,'stringCount’));
    This will give you the results you saw in both php4 and php5. You could also just register all lowercase to produce portable results, but if your goign to specify methods you might as well use case since it makes for nicer javascript.

  35. 35
    Marcus Bointon Said:

    I’ve got a bunch of miscellaneous global functions that I want to expose to Ajax. I’ve built a wrapper class that uses __call to call them as if they were class methods, and it works very nicely. However, I’m guessing that you use introspection to get method names, which you can’t get when they’re hidden behind a __call construct, so HTML_Ajax will be unable to construct a stub. How might I work around that?

  36. 36

    Marcus:
    Look at my post above, you can specify the methods to export, when you register the class allowing you to register virtual functions.

  37. 37

    Tried it. The examples are working fine.

    But, I have a problem.

    I tried out the example “review” inside the example directory. I played around a bit with it. Tried to modify it by instantiating another class from inside the newReview function. But it doesn’t work. What might be the problem? :(

  38. 38

    I’m not really sure what you’re trying to do. On the PHP side its just normal PHP code, one thing that might be causing you problems is that your code is expected to work under E_ALL error handling by default.

    The best thing to do is create a quick test script that runs your PHP class outside of the AJAX context.

    If its a problem exporting a class to the AJAX side there are a couple of things to check. First check your server file and make sure its being exported correctly. Then check the generated stub server.php?stub=classname for example, you can check the case etc here, and then make sure its being included into the page your trying to use it.

    If you have have some code you want to show to make things more clear feel free to send a message to the mailing list: http://lists.bluga.net/mailman/listinfo/html_ajax-devel

  39. 39

    I’m having some problems getting this to work. PHP 5.0.4, HTML_AJAX 0.3.3. tried on both linux and windows (server side). client side was tried on windows only.

    tried both firefox 1.5 and IE 6 (I think. Help|about just says side-by-side mode for version).

    The js console from firefox shows the following error on pageload:
    remoteHW.stringcount is not a function
    when i click on the approriate buttons i get:
    remoteHW.randomstring is not a function
    remoteHW.addstring is not a function

    I’m no expert on js, so i’m not sure why it’s not a function. calling the auto_server.php with the same args as used in the index.php results in a very impressive js file where I do see that function.

    any ideas?

  40. 40

    Ed:
    Sorry about that the problem is that php4 doesn’t support case and php5 does. The example above was created to run in php4 and doesn’t take the needed steps to make it work in php5. You can fix this problem by set the class and method names when registering the class on the server.

    So you have 2 options to make things work, change the javascript code to use case in all the method calls, (take a look at auto_server.php?stub=helloworld you’ll get an idea of what i mean), or register the methods all lower case.

    You can do this when you register the class change:
    $this->registerClass($hello);
    to:
    $this->registerClass($hello,’helloworld’,array(‘addstring’,'randomstring’,'stringcount’));

  41. 41

    Aha! That did the trick. And I see the answer was given in #14. doh.

    Now it’s time to play around and see what I can figure out.

    Thanks, and good work Joshua

  42. 42

    It would be helpful if you said what to call each file.

  43. 43

    Jim, im not sure what you mean file names shouldn’t matter. Just download the included code to see what i named things.

  44. 44
    Riccardo Tacconi Said:

    The big problem with HTML_AJAX is that there is not a real API docs. I fell clueless. I am just able to use submitForm and replace function :-(

  45. 45

    Riccaro:
    Yeah API doc wise we are hurting, but
    Have a look at the examples directory, there is an example of every method and every use case in there.

  46. 46
    Jochen Schneider Said:

    Joshua, nice job so far. But i’m running in a problem right away testing a lil bit. I’m trying to use “autocomplete” in a form. I want to type some letters and get the result not in a div-container, but as a hidden textfield, so i can read the result when i press the submit button.
    Am i totally wrong?! Or could you hint me a bit?
    Thx a lot in advance!
    Jochen

  47. 47

    Jochen:

    If you can use gpl code, I’ve written some autocomplete/suggest code that does that: http://svn.op-en.org/filedetails.php?repname=celini&path=%2Ftrunk%2Fjs%2Fsuggest.js&rev=0&sc=0

    Otherwise I would start from the queue_usage example and build from there.
    http://bluga.net/projects/HTML_AJAX/examples/queue_usage.php

  48. 48

    Hi,
    Can anyone help me how to pass a variable that is get from ‘prompt()’ javascript function to php. I tried looking at the forum and mailing archive but I couldn’t find anything.

    I’m trying to insert a new record on a table. It’s working but I can retrieve the data straight away.
    e.g:
    If I do an INSERT, Then the next thing is SELECT statement. It won’t give my anything.
    However when the script finished, and I do a SELECT statement again. It will give me the result.

    Thanks in advance.

  49. 49

    Cenil: im really not sure what your trying to do, but you can pass the variable from prompt just like any other javascript variable, you make some sort of AJAX call.

    Ask on the HTML_AJAX mailing list if you have any specific code you want me to look at.

  50. 50

    I’m looking at this and wondering, “why?”

    Is there a problem that HTML_AJAX is trying to solve? For some reason, I feel like it’s violating the MVC model of programming *and* doing something that’s typically considered a no-no … code writing code (php writing javascript functions).

    I typically use a prototype/json/php combination with a single php file that acts as the ‘ajax server’. I use various get variables and a switch statement to decide which classes to include and execute.

    Is this one of those “there’s more than one way to do it” approaches or am I missing the point?

  51. 51

    Jon:
    There are a lot of different ways to do this, and HTML_AJAX supports all of them.

    So HTML_AJAX_Server handles the PHP side, and you can either use generated stubs for easier JS programming or use a different API, HTML_AJAX.call etc for calling to the server without te stubs.

  52. 52

    What and/or where do files get installed – pear install HTML_AJAX-alpha

  53. 53

    Found it usr/lib/php/HTML/AJAX/ on OS X
    What web servers can this run on, other than apache?

  54. 54

    Frank: it should work on pretty much any web server, the only caveat being that it does use some variables in $_SERVER and im not sure if every server sets them. But I think those can all be worked around by setting the server url by hand.

  55. 55
    A'Quessir Said:

    Hi. Don’t you know, where can i find free eBooks(or even articles) on AJAX&PHP?

  56. 56

    A’Quessir: There are some articles linked in my AJAX resources list – http://blog.joshuaeichorn.com/ajax-resources/article/

  57. 57

    I’ve installed the HTML_AJAX package and setup your tutorial script on my site, but I cannot get it to run. I’m getting a javascript error on line 22 of index.php (helloworld is not defined)

    var remoteHW = new helloworld(hwCallback);

    All I’ve done is untar the scripts and pointed my browser at them.

    I’m running php 4.4.2

    Any ideas?

    http://test.bourbonhours.com/HTML_AJAX-HelloWorld/

  58. 58

    Check your error log, the libraries and generated AJAX stubs aren’t loading.

    http://test.bourbonhours.com/HTML_AJAX-HelloWorld/auto_server.php?client=all&stub=helloworld
    should be displaying a bunch of js content

  59. 59

    i can’t get it how do it work

  60. 60

    IC: I’m not sure what you mean, if you have a specific error please email the HTML_AJAX mailling list and one of us will get things worked out for you

  61. 61

    [...] HTML_AJAX supports a number of different ways to add AJAX to your pages, in this case I’ve chosen to use its PHP remoting supporting. This works registering a PHP class to be used by JavaScript, and then using a proxy object from JavaScript to make calls or making calls with the classname and methodname specified. Since im only going to be making a few calls im not going to be using a proxy object, if you want some examples on how that works checkout my Hello World with HTML_AJAX post. [...]

  62. 62

    Google Map Application Tutorial…

    Finally got an archive together, a few bugs knocked out, and a little more documentation. You can download the file here.

    Here are a few references (until I get some slides put together).

    GoogleMapAPI PHP Class:
    http://www.phpinsider.com/php/co...

  63. 63

    Hi all!

    Just yesterday AJAX caught my attention. Im writing text-based games
    in PHP in my spare-time using static java-script to produce the output and always considered that techtnique too complicated.

    So reading my first pages about PEAR and AJAX, this sounds very promissing to me.

    The example HelloWorld I got to run on PHP5 changing to caps as well.
    For now I would like tzo follow this track as I just finished a course in java-2 including some webdevelopping and enjoy to find classes here again. I will try to make a little game using ajax, hoping I can make it support some action ;)

    Greetings to all, keep on the nice work! Ralf

  64. 64

    Hello Joshua, I’m am new to HTML_AJAX, I downloaded your sample code and I even changed register line as you indicated above. However, the script doesn’t respond to the button clicks talkless of sending the input.

    You help would be greatly appreciated.

  65. 65

    Hi all,

    I was just looking at the example formSubmit in the HTML_AJAX bundled docs and am a little confused; in order to execute a submit with formSubmit you need to post from form.php to server.php so I might as well just use an html form and handle the post server-side in a regular manner. Am I missing the point of formSubmit completely? I’m really amp-ed to use HTML_AJAX but the lack of documentation is killing me. If anyone could point me in the direction of a HTML_AJAX form submit tutorial or even a snippet of code it’d be much appreciated.

  66. 66

    mrhavercamp:
    Take a look at http://bluga.net/projects/HTML_AJAX/examples/form.php

    In the basic case its just:
    <form action=”server.php” method=”post” onsubmit=”return !HTML_AJAX.formSubmit(this)”>

  67. 67
    wang suya Said:

    I tryed Webpage http://wiki.bluga.net/HTML_AJAX/start? example

    A basic server is shown below, in the file server.php:

    handleRequest();
    ?>

    page.html:

    I’m the target

    HTML_AJAX.replace(‘target’,'output.php’);

    output.php:

    “. strftime(“%H:%M:%S”) .”");
    ?>

    but it only show onetime time and it was not our local time(Japan) it was 11:17:02. Then I push the button but the time did not change. I tryed to change the output.php’s output contents but it was not reflected still 11:17:02. Do I have to download the all the js file in my server how can I download them? or do I have to setup our server’s proxy? I am run PHP5.
    Thank you very much.

  68. 68

    HTML_AJAX needs to be installed on your server to use it. You can use PEAR to do the installation.

  69. 69
    wang suya Said:

    I installed HTML_AJAX by PEAR into my server, but I looked at there is no .js file.

  70. 70

    Wang:
    http://htmlajax.org/HTML_AJAX/Manual?#toc5

    On most unix systems that would be:
    /usr/share/pear/data/HTML_AJAX/js/HTML_AJAX.js

    HTML_AJAX_Server knows where the files are and handleRequest can server up the JavaScripts libs if you wnat

  71. 71
    wang suya Said:

    Joshua: I installed Pear in /usr/local/lib/php. because my php installed here and core pear was installed hear, too. You mean I shoud install pear in /usr/share/pear/ then the js file will automatically installed in /usr/share/pear/data/HTML_AJAX/js/HTML_AJAX.js. Therefore I should move core pear from /usr/local/lib/php to /usr/share/pear but it will seperate from php is it ok?

  72. 72
    wang suya Said:

    Joshua: I download the HTML_AJAX from http://htmlajax.org/HTML_AJAX/Manual?#toc5

    then I still keep my PEAR in /usr/local/lib/php. I mv js to /usr/local/lib/php/HTML/js. I installed HTML_AJAX from command line use pear install HTML_AJAX-beta. I follow the manual add one line $server->jsClientLocation = ‘/usr/local/lib/php/HTML/js’; in the
    Webpage http://wiki.bluga.net/HTML_AJAX/start? example, but it does not work, too. I push the button, but the time still not change. Could tell me why?

  73. 73
    wang suya Said:

    I found js file when I installed HTML_AJAX. It is in /usr/local/lib/php/data/js. But when I run Webpage http://wiki.bluga.net/HTML_AJAX/start? example it just show time once and when I push the button, it does not change. Why

  74. 74

    Wang: no clue are you getting any javascript errors?

  75. 75
    wang suya Said:

    Joshusa: I installed Firefox then try this example. It correctly worked. But Use IE to run this example it did not work. I do not know how to investiage javascript errors in IE. Do you know why IE does not work?

  76. 76

    Wang: Things are working fine here in ie7 and the as yet unreleased HTML_AJAX 0.5.1

    I tested things at:
    http://blog.joshuaeichorn.com/examples/HTML_AJAX-HelloWorld/

  77. 77
    wang suya Said:

    Joshua: My IE is version 6. Maybe is it the problem? I test HTML_AJAX use http://htmlajax.org/HTML_AJAX/Manual?#toc5 “RunIT” it poped up HelloWorld. But that example does not work.

  78. 78
    wang suya Said:

    Joshua: I tryed http://blog.joshuaeichorn.com/examples/HTML_AJAX-HelloWorld in my IE6. It worked.

  79. 79
    wang suya Said:

    Joshua: I tryed HTML_AJAX’s exmaples in IE6, some worked and others did not work. for example Form.php in IE6 it did not work but in Firefox it worked. Why?

  80. 80

    If something doesn’t work in IE6 you’ve found a bug.

    Try using the 0.5.1 testing build it has a couple ie6 fixes:
    http://htmlajax.org/HTML_AJAX/release-0.5.1?

  81. 81
    wang suya Said:

    Joshua: I downloaded HTML_AJAX-0.5.1 then move it to server:/usr/local/lib/php/ and unfreeze it, tar it, but it could not be tared. Why?

  82. 82
    wang suya Said:

    Joshua: I try to use HTML_AJAX.replace as bellow:

    function settd(){
    if(document.f.a1.checked){
    HTML_AJAX.replace(‘target’,'output.php’);
    }
    }

    I’m the target

    but it does not work. I try to realize that when I check the checkbox then one php file be excuted. In php file DB access and dom access are excuted. How can I use HTML_AJAX to realize it?

  83. 83
    wang suya Said:

    It seem that html file could not replay to maillist. The checkbox
    click is simplized like ” input type = “checkbox” name = “a1″ onClick = “settd()”

  84. 84

    Wang: can you take these questions to the mailing list, its hard to follow this much on a forum plus were really not releated to the post anymore.

    http://lists.bluga.net/mailman/listinfo/html_ajax-devel

  85. 85

    Hi,

    I get a request time out error of 20000ms. How can I change this number to something like 40,000ms?

    Thanks
    Prem

  86. 86

    Prem:
    remoteHW.dispatcher.timeout = 40000;

  87. 87
    wang suya Said:

    Joshua: 4 weeks ago, you told me to use http://htmlajax.org/HTML_AJAX/release-0.5.1?
    but I download it then refreeze it and tar it but it did not success. When I tar it
    there are the message like :” XXXX are not directory”.
    I throwed this question to maillist you told me but no response.

  88. 88

    Wang: Did you try using the pear installer, there might be some issues with the tarball but since it was made with the pear insaller there shouldn’t be any issues with it extracting it.

  89. 89

    [...] AJAX Hello World with HTML_AJAX [...]

  90. 90

    joshua: im new to php as well HTML_AJAX
    in auto_server.php we r doing…
    $server = new AutoServer();
    but how this is instantiating HTML_AJAX_Server() object.
    this might be a Class concept,can u explain how
    $server = new AutoServer() is doing work for HTML_AJAX_Server() class

  91. 91

    AutoServer extends HTML_AJAX_Server and adds in the initClassName methods

    http://www.php.net/manual/en/language.oop5.basic.php

  92. 92

    [...] Joshua Eichorns Blog » Blog Archive » AJAX Hello World with HTML_AJAX [...]

  93. 93

    Hi Joshua,

    I tried all I could to run your Hello World on my system, but I face something I never quite seen before in HTML (especially when I see none whatsoever)
    a Syntax Error (damn, that remind me of the good old GW-BASIC…)

    same thing with my typed version as well as your own version when copied/pasted… I don’t know where to look… I don’t know if it’s related, but after all maybe… my index.php is named helloworld.html (is there an issue with naming it .html instead of .php??)

    the syntax error is on line 2!!!

    excerpt: (I only suppose, eh…)

    Line 1:
    Line 2:
    Line 3: HTML AJAX Hello World
    Line 4:
    etc…

    any advice/help ??

    thanks :)

    Chris

  94. 94

    If your using ie6 then the provided line # means nothing. If you use ie7 or firefox you’ll get a more reasonable error message. Using .html instead of .php for the helloworld file shouldn’t matter since there is no php in that file.

  95. 95

    Do I need copy also the directory HTML/AJAX to the same directory I put the webpage?

    This is the first time I using PEAR. Therefore, I don’t know how it works.

    require_once ‘HTML/AJAX/Server.php’;
    Will PHP automatically find the place of the request page in PEAR (in this case, the page is Sever.php), or we have to indicate where it is?

    When I try the example, It doesn’t work unless I copy the directory HTML_AJAX to same place will example.

  96. 96

    Hi! I found the solution :D Sorry about my stupid question :D

    To make PEAR work on Windows, you simple need to add the PEAR installation dir (e.g. c:\php\pear) to the include_path directive in your php.ini.

    Note: There are some classes (like Schedule/At.php), that do not work on Windows, because they use *nix specific commands.

  97. 97
    pfarthing6 Said:

    the working example is broken. Javascript error: remoteHW has no properties. Using FF-2.0.0.6

    Also this seems like way too much work and code to just do a simple xmlHTTP request to get some data off of a server and place it somewhere in a document and just shouldn’t even need any session vars to do it.

  98. 98

    pfarthing6:

    The sessions are there because you want to store data in the session. AJAX doesn’t get rid of the need of sessions.

    Things were broken because of PHP5/PHP4 case differences

  99. 99

    Is it possible to set php class members without accessing a method.
    For example: changing the variable $d from the javascript remoteClass.d=4

    <?
    class a{

    var $d;

    function s(){}

    }

  100. 100

    Oren:

    HTML_AJAX doesn’t support this and you really wouldn’t want to do that anyway since making an http request to set a single variable would be horrible slow and inefficient

  101. 101

    [...] http://blog.joshuaeichorn.com/archives/2005/08/17/ajax-hello-world-with-html_ajax/ [...]

  102. 102

    Hi there,
    In my web page I have 2 different sections of the page that use AJAX to load information. The trouble i’m having is to work out how to have more than one loading message (‘HTML_AJAX_LOADING’) in the page. The reason I want this is to have the loading message next to the part that is loading so it doesn;t pop up at the wrong part of the screen. I’ve done many a web search and poked around but can’;t work out how to do it – is there a way round this you’d advise me to follow?
    thanks

  103. 103

    James:
    You have a couple different options, but in every case it amounts to creating custom Open/Load functions. The second parameter to each of the global methods (default: http://svn.bluga.net/HTML_AJAX/trunk/js/Loading.js) should be a Request object and you could use that for custom loading messages.

    But if you want loading at the spot of the call i think i would create custom methods for handling the message on the proxy object (or if your not using a proxy on the Request object)

    proxy.dispatcher.options['Open'] = function() { logic to show message here }
    proxy.dispatcher.options['Load'] = function() { logic to hide here }


Leave a Reply

This circle expands additional navigation