Sublime Forum

AJAX autocomplete?

#1

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” :neutral_face:

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 …

0 Likes

#2

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 :wink:

BTW Thisis a good reference page.

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(); };

0 Likes

#3

Thanks your reply, I will consider to removing packages which I don’t need to use. :smiley:

0 Likes

#4

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 :question:

0 Likes