Category Archives: javascript

jQuery – stop an ajax call!

It’s a simple task with no simple question, although in jQuery, as I mentioned now, everything is very simple. Even this task.

In a short example we’ve a simple AJAX call with very large request.

xhr = $.ajax({
    url : 'www.example.com?some-large-call',
    success : function(responseText) {
        // some DOM manipulation
    }
});

But what if something changes the data we’d like to request with this call even before the response has come. For example I click on a category in the site but before all the data has come I’d prefer to see other category’s data. Continue reading jQuery – stop an ajax call! →

javascript get locale month with full name

JavaScript Date object

The Date object in JS helps you work with dates as it sounds logical. However there are limited number of functions attached to it which you can use. You can check for full Date specification in w3schools : here.

How to get the month name?

Normally when you try to use a date object you can format it with the following code:

var d = new Date();
alert(d.getFullYear());
alert(d.getMonth());
alert(d.getDate());

The problem is that you cannot reference the date object and to get the full name of the month. Something like d.getFullMonth()!

That’s why the easiest way to get the full month name is to make a custom locale array such this one:

var monthLocale = new Array(12);
monthLocale[0] = "January";
monthLocale[1] = "February";
monthLocale[2] = "March";
monthLocale[3] = "April";
monthLocale[4] = "May";
monthLocale[5] = "June";
monthLocale[6] = "July";
monthLocale[7] = "August";
monthLocale[8] = "September";
monthLocale[9] = "October";
monthLocale[10] = "November";
monthLocale[11] = "December";

And than you can simply reference the locale array!

OpenLayers vectors IE bug!

OpenLayers and OpenStreetMap

If you’re not familiar with OpenLayers library, in breve this is a JavaScript library which interacts with a tile server such as this of OpenStreetMap.org

Vectors

Because it’s JavaScript OpenLayers library it renders different types of vectors when it becomes the case of vectors. It tries the VML way, but as you may know not every browser support it.  Actually everything works fine in every browser, and that’s the good part of OpenLayers, which is one of the best JavaScript organized project I’ve worked with.

The problem is that if you’ve something in the DOM with z-index over the vector layer IE’s giving problems because as it appears it cannot be rendered.

The solution is to draw the layer but skip the .addLayer before the vectors should be seen. You than remove the DOM element, which is over the vector layer you set .setVisibility(true) and the layer appears on the stage.

So far this is the only solution I got, but there may be others.