chrisdavies / alite Goto Github PK
View Code? Open in Web Editor NEWTiny, lightweight XMLHttpRequest wrapper
Tiny, lightweight XMLHttpRequest wrapper
Hi, i need to get some info from
http://openapi.ro/api/companies/13548146.json
and if i use alite like this:
alite({
url: 'http://openapi.ro/api/companies/13548146.json',
method: 'get',
dataType: 'jsonp'
}).then(function (result) { console.log(result); });
i get
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://openapi.ro/api/companies/13548146.json. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
but it works with
$.ajax({
type: 'get',
url: 'http://openapi.ro/api/companies/13548146.json',
dataType: 'jsonp',
success: function(data) {
console.log(data["state"]);
}
})
any hints on this
Thanks
Hi, first of all i want to thank you for this great utility, i use it and had no problems with it and i want to ask you if there is some way to add the context for this keyword, here is an example:
`var a = function () {
alite({
url: '/api/foo/bar',
method: 'POST',
data: { foo: 'bar' }
}).then(function (result) {
this.process(result);
})
}
a.prototype = {
process: function(result) {
... do something with the result ...
},
....
}`
this.process is not available so i have to assign a new variable to this "var _this = this; " and call the _this.process(value). is there any way i can pass the scope without creating this new variable?
Thanks
Hi, i didn't get a change to thank you for your help and responses ๐ and here i am with another question, is it possible to post simple data say a=1 without creating a FormData() or sending json array?
For now i do this:
var data = new FormData();
data.append('a','1');
alite({
url: url,
method: 'post',
data: data,
raw: true
});
and if i try to send
data = "a=1";
I get a post request without name and value "a=1"
Thanks
Hi, i have added a multipart/form-data to a test project (it has some text inputs and one file input) and i am using this function onsubmit
function post(url,form) {
var data = new FormData(form);
return alite({
url: url,
method: 'post',
data: data,
raw: true
});
}
is this the right way to do this or do i have to specify Content-Type, Content-Disposition ...
Thank you
Hi, I've added one loading element to my page and i want to display it while waiting for response,
I am using alite.min.js and i change it like this:
//to show my element PSI.Utils.loading is a simple function that hide/show my loading element
new Promise(function(n,r){PSI.Utils.loading(true);var s=...
//to hide my loading element
s.onreadystatechange=function(){4==s.readyState&&(s.status>=200&&s.status<300?(n(a(s)),PSI.Utils.loading(false)):r(a(s)),(PSI.Utils.curl.ajaxStop||t)(s,e))}
Is this correct? Or is there a better way to do this?
The problem is that it won't hide for 404's responses... I could do that:
s.onreadystatechange=function(){4==s.readyState&&(s.status>=200&&s.status<300?(n(a(s)),PSI.Utils.loading(false)):(r(a(s),PSI.Utils.loading(false))),(PSI.Utils.curl.ajaxStop||t)(s,e))}
but it doesn't seem OK to me :)
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.