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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-08-04 08:01:04 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:976
Trampoline: Fixing small typo since we're really trying to limit the physical 
data in memory and have very little interest in core files (short of not 
wanting them).  Curiously it doesn't seem to stop me allocating ~512MB of 
data... Is this something to do with malloc being able to do MAP_ANONYMOUS 
mmap?

Show diffs side-by-side

added added

removed removed

Lines of Context:
538
538
    return str.substr(str.length - substring.length) == substring;
539
539
}
540
540
 
 
541
/** Equivalent to Python's repr.
 
542
 * Gets the JavaScript string representation.
 
543
 * Actually just calls JSON.stringify.
 
544
 */
 
545
function repr(str)
 
546
{
 
547
    return JSON.stringify(str);
 
548
}
 
549
 
541
550
/** Removes all occurences of a value from an array.
542
551
 */
543
552
Array.prototype.removeall = function(val)
622
631
 * \param app IVLE app to call (such as "fileservice").
623
632
 * \param path URL path to make the request to, within the application.
624
633
 * \param args Argument object, as described in parse_url and friends.
625
 
 * \param method String; "GET", "POST", "PUT", or "PATCH"
626
 
 * \param content_type String, optional.
 
634
 * \param method String; "GET" or "POST"
 
635
 * \param content_type String, optional. Only applies if method is "POST".
 
636
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
627
637
 *      Defaults to "application/x-www-form-urlencoded".
628
638
 */
629
639
function ajax_call(callback, app, path, args, method, content_type)
630
640
{
631
 
    if (!content_type)
 
641
    if (content_type != "multipart/form-data")
632
642
        content_type = "application/x-www-form-urlencoded";
633
643
    path = app_path(app, path);
634
644
    var url;
658
668
    }
659
669
    else
660
670
    {
661
 
        /* POST & PUT & PATCH sends the args in the request body */
 
671
        /* POST sends the args in application/x-www-form-urlencoded */
662
672
        url = encodeURI(path);
663
673
        xhr.open(method, url, asyncronous);
664
674
        var message;
668
678
                "multipart/form-data; boundary=" + boundary);
669
679
            message = make_multipart_formdata(args, boundary);
670
680
        }
671
 
        else if (content_type == "application/x-www-form-urlencoded")
 
681
        else
672
682
        {
673
683
            xhr.setRequestHeader("Content-Type", content_type);
674
684
            message = make_query_string(args);
675
685
        }
676
 
        else if (content_type == "application/json")
677
 
        {
678
 
            xhr.setRequestHeader("Content-Type", content_type);
679
 
            message = JSON.stringify(args);
680
 
        }
681
 
        else
682
 
        {
683
 
            xhr.setRequestHeader("Content-Type", content_type);
684
 
            message = args;
685
 
        }
686
686
        xhr.send(message);
687
687
    }
688
688
    /* Only return the XHR for syncronous requests */