Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Wednesday, November 5, 2014

How jQuery is written from scratch?

This probably helps: http://www.mikedoesweb.com/2012/creating-your-own-javascript-library/

This is a minimum javascript library whose grammar is very similar to jQuery: _('id').function(). It helps to understand how jQuery is written from scratch.

I think I can start writing a javascript library similar to jQuery now :).

Tuesday, October 21, 2014

jQuery 1.8 update on ajax call

jQuery ajax call uses different syntax since version 1.8 [1].


Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8 (but still works in 1.9.1). To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

Get html in jQuery before 1.8:

$.ajax({
    url: 'test.html',
    dataType: 'html',
    success: function (data, textStatus, xhr)
    {
        console.log(data);
    },
    error: function (xhr, textStatus, errorThrown)
    {
        console.log('error: '+textStatus);
    }
});


The code above still works in 1.8. But the code below no longer works in 1.8:

$.post("get_news.php", { id: id }, function(data, status) {
    if (status == "success") {
        if ( data != '' ) {
            o.innerHTML = data;
        }
        return 1;
    } else {
        return 1; // ok
    }
}, 5);


Get html in jQuery since 1.8:

// cache: false is used to fetch the latest version
$.ajax({

    type: 'POST',
    url: "test.html",

    data: { id: id },
    dataType: 'html',
    cache: false
})
.done(function(data, textStatus, jqXHR)
{
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown)
{
    console.log('error: '+textStatus);
});



[1] http://www.sitepoint.com/ajax-jquery-1-8/

Wednesday, April 18, 2012

"Same Domain Policy" limitation of jQuery

The same domain policy prevents javascripts hosted on one domain from accessing data from a remote domain. This is for security purpose. So when use jQuery, you can not directly access a web service from a remote server.

The solution is to create a serverside script (for example, in php, as shown below) on your domain, which will serve as a proxy, get the data from the remote domain, and then output it. For example:

<?php
readfile('http://remote_server.com/service?param=' . urlencode($_GET['param']);
?>

[1] Getting data from remote URL using jquery
[2] Cross-domain requests with jQuery

Monday, June 6, 2011

jQuery, Charting

http://jquery.com/
flot - Javascript plotting for jQuery : draws on the canvas element (For IE version earlier than 9, needs excanvas JavaScript emulation helper and canvas-text). Purposes are easy use, attractive look, and interactive features.
Google charts - This is actually closed source. The JavaScript is compacted, and loads libraries dynamically at runtime.

用于图片处理的10个超级jQuery插件
Comparison: Javascript框架和jQuery

Blog Archive

Followers