Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding post request support #41

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ var geojsonLayer = L.geoJson.ajax("route/to/esri.json",{
});
```

You can also use a post request by supplying post parameters :

```javascript
var geojsonLayer = L.geoJson.ajax("route/to/esri.json",{
post : {postField : 'data1'}
});

//or

geojsonLayer.refresh("route/to/esri.json", postData);
```


addUrl does not clear the current layers but adds to the current one, e.g.:

```javascript
Expand Down
171 changes: 90 additions & 81 deletions dist/leaflet.ajax.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,77 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
'use strict';
var Mutation = global.MutationObserver || global.WebKitMutationObserver;

var scheduleDrain;

{
if (Mutation) {
var called = 0;
var observer = new Mutation(nextTick);
var element = global.document.createTextNode('');
observer.observe(element, {
characterData: true
});
scheduleDrain = function () {
element.data = (called = ++called % 2);
};
} else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
var channel = new global.MessageChannel();
channel.port1.onmessage = nextTick;
scheduleDrain = function () {
channel.port2.postMessage(0);
};
} else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
scheduleDrain = function () {

// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var scriptEl = global.document.createElement('script');
scriptEl.onreadystatechange = function () {
nextTick();

scriptEl.onreadystatechange = null;
scriptEl.parentNode.removeChild(scriptEl);
scriptEl = null;
};
global.document.documentElement.appendChild(scriptEl);
};
} else {
scheduleDrain = function () {
setTimeout(nextTick, 0);
};
}
}

var draining;
var queue = [];
//named nextTick for less confusing stack traces
function nextTick() {
draining = true;
var i, oldQueue;
var len = queue.length;
while (len) {
oldQueue = queue;
queue = [];
i = -1;
while (++i < len) {
oldQueue[i]();
}
len = queue.length;
}
draining = false;
}

module.exports = immediate;
function immediate(task) {
if (queue.push(task) === 1 && !draining) {
scheduleDrain();
}
}

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
'use strict';
var immediate = require('immediate');

Expand Down Expand Up @@ -253,80 +326,7 @@ function race(iterable) {
}
}

},{"immediate":2}],2:[function(require,module,exports){
(function (global){
'use strict';
var Mutation = global.MutationObserver || global.WebKitMutationObserver;

var scheduleDrain;

{
if (Mutation) {
var called = 0;
var observer = new Mutation(nextTick);
var element = global.document.createTextNode('');
observer.observe(element, {
characterData: true
});
scheduleDrain = function () {
element.data = (called = ++called % 2);
};
} else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
var channel = new global.MessageChannel();
channel.port1.onmessage = nextTick;
scheduleDrain = function () {
channel.port2.postMessage(0);
};
} else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
scheduleDrain = function () {

// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var scriptEl = global.document.createElement('script');
scriptEl.onreadystatechange = function () {
nextTick();

scriptEl.onreadystatechange = null;
scriptEl.parentNode.removeChild(scriptEl);
scriptEl = null;
};
global.document.documentElement.appendChild(scriptEl);
};
} else {
scheduleDrain = function () {
setTimeout(nextTick, 0);
};
}
}

var draining;
var queue = [];
//named nextTick for less confusing stack traces
function nextTick() {
draining = true;
var i, oldQueue;
var len = queue.length;
while (len) {
oldQueue = queue;
queue = [];
i = -1;
while (++i < len) {
oldQueue[i]();
}
len = queue.length;
}
draining = false;
}

module.exports = immediate;
function immediate(task) {
if (queue.push(task) === 1 && !draining) {
scheduleDrain();
}
}

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
},{"immediate":1}],3:[function(require,module,exports){
(function (global){
'use strict';
var jsonp = require('./jsonp');
Expand All @@ -346,7 +346,7 @@ module.exports = function (url, options) {
}
var response;
request = new global.XMLHttpRequest();
request.open('GET', url);
request.open((Object.keys(options.post).length > 0)?'POST':'GET', url);
request.onreadystatechange = function () {
if (request.readyState === 4) {
if ((request.status < 400 && options.local) || request.status === 200) {
Expand All @@ -365,7 +365,14 @@ module.exports = function (url, options) {
}
}
};
request.send();
if(Object.keys(options.post).length > 0)
{
request.send(options.post);
}
else
{
request.send();
}
});
out.catch(function (reason) {
request.abort();
Expand All @@ -376,7 +383,7 @@ module.exports = function (url, options) {
};

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./jsonp":5,"lie":1}],4:[function(require,module,exports){
},{"./jsonp":5,"lie":2}],4:[function(require,module,exports){
(function (global){
'use strict';
var L = global.L || require('leaflet');
Expand All @@ -389,7 +396,8 @@ L.GeoJSON.AJAX = L.GeoJSON.extend({
local: false,
middleware: function (f) {
return f;
}
},
post:{}
},
initialize: function (url, options) {
this.urls = [];
Expand Down Expand Up @@ -473,8 +481,9 @@ L.GeoJSON.AJAX = L.GeoJSON.extend({
}
});
},
refresh: function (url) {
refresh: function (url,post) {
url = url || this.urls;
this.ajaxParams.post = post || {};
this.clearLayers();
this.addUrl(url);
},
Expand Down Expand Up @@ -513,7 +522,7 @@ L.geoJson.ajax = function (geojson, options) {
};

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./ajax":3,"./jsonp":5,"leaflet":undefined,"lie":1}],5:[function(require,module,exports){
},{"./ajax":3,"./jsonp":5,"leaflet":undefined,"lie":2}],5:[function(require,module,exports){
(function (global){
'use strict';
var L = global.L || require('leaflet');
Expand Down Expand Up @@ -567,4 +576,4 @@ module.exports = function (url, options) {
};

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"leaflet":undefined,"lie":1}]},{},[4]);
},{"leaflet":undefined,"lie":2}]},{},[4]);
Loading