Home Download Buy Blog Forum Support

AJAX autocomplete?

AJAX autocomplete?

Postby Doraemon on Sat Oct 06, 2012 11:24 am

Hi everyone, I begin to practice examples about AJAX. I installed pretty much package related to JS. (Jquery Snippets Pack, JSFormat, JSHint, Autocomplete Javascript with method signature, SublimeCodeIntel) but seems ST don't support keywords of AJAX. I have following snippet:

var Request = false;

if (window.XMLHttpRequest) {
Request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
Request = new ActiveXObject("Microsoft.XMLHTTP");
}

I must type XMLHttpRequest, ActiveXObject "by hand" :|

If i dive deeply into AJAX, ST becomes weak ...

Request.onreadystatechange = function()
{
if (Request.readyState == 4 && Request.status == 200) {
RequestObj.innerHTML = Request.responseText;
}
}

Obviously, ST can't hint for other methods which exist into Request variable ...
Doraemon
 
Posts: 16
Joined: Fri Sep 07, 2012 1:56 am

Re: AJAX autocomplete?

Postby agibsonsw on Sat Oct 06, 2012 12:27 pm

JS is a dynamic language and so it is unable to provide the context-sensitive completions that you are looking for. That is, it doesn't know what Request might be.

My AndyJS completions (available via PackageControl) contains many of the terms in your code, but you already have three alternative sets of snippets/completions. You shouldn't just load everything JS related, as this will cause confusion and possible conflict.

Eventually you might consider creating utility functions for ajax similar to the following, as the code always follows the same pattern. Then you'll never need to type onreadystatechange again ;)

BTW Thisis a good reference page.

Code: Select all
var loadJSON = function (url, cfunc) { 
    // requires a callback function to handle the response data
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {            // code for IE
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        var jsonData;
        if ( xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            jsonData = JSON.parse(xmlhttp.responseText);
            cfunc(jsonData);
        }
    };
    xmlhttp.open("GET", url, true);
    xmlhttp.send();
};
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: AJAX autocomplete?

Postby Doraemon on Sat Oct 06, 2012 11:57 pm

Thanks your reply, I will consider to removing packages which I don't need to use. :D
Doraemon
 
Posts: 16
Joined: Fri Sep 07, 2012 1:56 am

Re: AJAX autocomplete?

Postby agibsonsw on Sun Oct 07, 2012 1:20 am

Doraemon wrote:Thanks your reply, I will consider to removing packages which I don't need to use. :D

Using PackageControl you can disable packages. This will help you to discover which are the most helpful before uninstalling.

BTW SublimeCodeIntel is quite poor/not maintained and is being replaced - but I've forgotten the new name for this package :?:
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to General Discussion

Who is online

Users browsing this forum: MrMartineau, Orlmente and 27 guests