~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/common/util.js

  • Committer: mattgiuca
  • Date: 2008-02-19 06:10:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:503
user.py: Added acct_expired and pass_expired methods.
login.py: Removed has_expired function (now we put it inside the class)
    and called those methods instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
519
519
    arr.splice(j, i-j);
520
520
}
521
521
 
522
 
/** Returns a new XMLHttpRequest object, in a somewhat browser-agnostic
523
 
 * fashion.
524
 
 */
525
 
function new_xmlhttprequest()
526
 
{
527
 
    try
528
 
    {
529
 
        /* Real Browsers */
530
 
        return new XMLHttpRequest();
531
 
    }
532
 
    catch (e)
533
 
    {
534
 
        /* Internet Explorer */
535
 
        try
536
 
        {
537
 
            return new ActiveXObject("Msxml2.XMLHTTP");
538
 
        }
539
 
        catch (e)
540
 
        {
541
 
            try
542
 
            {
543
 
                return new ActiveXObject("Microsoft.XMLHTTP");
544
 
            }
545
 
            catch (e)
546
 
            {
547
 
                throw("Your browser does not support AJAX. "
548
 
                    + "IVLE requires a modern browser.");
549
 
            }
550
 
        }
551
 
    }
552
 
}
553
 
 
554
 
/** Makes an asynchronous XMLHttpRequest call to the server.
555
 
 * Sends the XMLHttpRequest object containing the completed response to a
556
 
 * specified callback function.
 
522
/** Makes an XMLHttpRequest call to the server. Waits (synchronously) for a
 
523
 * response, and returns an XMLHttpRequest object containing the completed
 
524
 * response.
557
525
 *
558
 
 * \param callback A callback function. Will be called when the response is
559
 
 *      complete. Passed 1 parameter, an XMLHttpRequest object containing the
560
 
 *      completed response.
561
526
 * \param app IVLE app to call (such as "fileservice").
562
527
 * \param path URL path to make the request to, within the application.
563
528
 * \param args Argument object, as described in parse_url and friends.
565
530
 * \param content_type String, optional. Only applies if method is "POST".
566
531
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
567
532
 *      Defaults to "application/x-www-form-urlencoded".
 
533
 * \return An XMLHttpRequest object containing the completed response.
568
534
 */
569
 
function ajax_call(callback, app, path, args, method, content_type)
 
535
function ajax_call(app, path, args, method, content_type)
570
536
{
571
537
    if (content_type != "multipart/form-data")
572
538
        content_type = "application/x-www-form-urlencoded";
576
542
     * (This is not checked against anywhere else, it is solely defined and
577
543
     * used within this function) */
578
544
    var boundary = "48234n334nu7n4n2ynonjn234t683jyh80j";
579
 
    var xhr = new_xmlhttprequest();
580
 
    xhr.onreadystatechange = function()
581
 
        {
582
 
            if (xhr.readyState == 4)
583
 
            {
584
 
                callback(xhr);
585
 
            }
586
 
        }
 
545
    var xhr = new XMLHttpRequest();
587
546
    if (method == "GET")
588
547
    {
589
548
        /* GET sends the args in the URL */
590
549
        url = build_url({"path": path, "args": args});
591
 
        /* open's 3rd argument = true -> asynchronous */
592
 
        xhr.open(method, url, true);
 
550
        /* open's 3rd argument = false -> SYNCHRONOUS (wait for response)
 
551
         * (No need for a callback function) */
 
552
        xhr.open(method, url, false);
593
553
        xhr.send(null);
594
554
    }
595
555
    else
596
556
    {
597
557
        /* POST sends the args in application/x-www-form-urlencoded */
598
558
        url = encodeURI(path);
599
 
        xhr.open(method, url, true);
 
559
        xhr.open(method, url, false);
600
560
        var message;
601
561
        if (content_type == "multipart/form-data")
602
562
        {
612
572
        xhr.setRequestHeader("Content-Length", message.length);
613
573
        xhr.send(message);
614
574
    }
 
575
    return xhr;
615
576
}
616
577