ded / reqwest Goto Github PK
View Code? Open in Web Editor NEWbrowser asynchronous http requests
browser asynchronous http requests
Looks like IE/JSONP broke hard at some point - I'm getting a mix of errors (nothing coming back) and multiple requests at the same time coming in out of order with with the wrong data assigned to each.
To build you need smoosh. This is not documented in README or package.json.
Hi!
How do i set request headers, in particular, Content-Type:
TIA,
--Vladimir
As soon as Reqwest is added into my Ender build, my minified Ender script gets a syntax error. Running Ender v1.0.1. Reproducible as:
ender build reqwest
Then when including ender.min.js
on the page:
Uncaught SyntaxError: Unexpected token (
The uncompressed ender.js
file still works okay, and interestingly, also works fine when compressed with another service (such as closure compiler).
Al through there are samples for failure callback it's never called
Hi,
Would it be possible for you to tag point releases so we can properly integrate Reqwest with package management solutions such at Bower or Yeoman.
We are currently using Reqwest with Bower, but having to supply "*" as the version dependency in component.json - which is OK - but dangerous as doesn't allow us to force a specific version for backwards compatibility.
The other solution is for Bower to support commit SHA's as versions but it doesn't look like they will be doing this anytime soon (bower/bower#107), as they (quite rightly) see tagging as the correct way to go about doing this.
I don't expect you to go back through and create tags for old versions, but having one for latest 0.6.0 and onwards would be great π
Thoughts?
Would it be possible add in an option to make the AJAX call synchronous instead of always asynchronous? I'm trying to use this with window.onbeforeunload and it won't fire off the call unless FALSE is passed in the third parameter or http.open()
.
Cheers,
meenie
The eval calls should be removed from the library. Using eval can potentially expose cross-site scripting vulnerabilities. Remove eval from the built-in success function and have the user consciously call it himself inside his own success function if required.
An alternative is to have a response type called "eval" and definitely not have this defaulted. Eval is bad!
I was transferring a website from jQuery to Ender when I get this unpleasant surprise Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Here the jQuery code.
Here the Ender code.
I added a commit note here:
The problem is that module.exports is never assigned to in reqwest.js, but ender.js tries to require it. This means that it will work fine as a standalone package, but will break when used as an ender package.
Could you elaborate on why this is more useful than jQuery's built-in xhr functionality, especially since you specifically you seem to indicate at the end that it is a useful replacement alongside jQuery? Speaking for the clueless idiot, such as myself, of course.
I use qwery to get the form node, I would like to pass it the node and reqwest to create a default ajax reqwest based on all the information provided by the form.
If you want it in and can't find time for it, I can create a pull request for it.
In IE 9 and 10 there are a few tests failing in the XML
group and the test stop running at MODULE: Cross-origin Resource Sharing
.
First of all I love the module! Using the commonjs structure rocks. I'm currently working on a platform that needs some specific browser tweaks, I have to call a custom xhr.destroy() function after a request. Unfortunately this does not seem possible with the current success callback, as it does not provide the used xhr object. Or am I missing something?
Maybe it is an idea to support a default setup solution just like jquery with "ajaxSetup"
http://api.jquery.com/jQuery.ajaxSetup/
Thanks!
When concatenating reqwest with other scripts it can lead to issues because of the missing trailing semicolon. Would be great if you could add it.
Wombat-2:reqwest Kelly$ git submodule init
No submodule mapping found in .gitmodules for path 'build/connect'
Can't run the tests since the submodules can't be init.
Right now, the error()
function just gets the XMLHttpRequest
object (contrary to what the docs suggest).
It would be great if the first argument would be an error object containing the content and the parsed content if available (if the content-type was JSON it should already be parsed JSON).
tests.html still refers to valentine, and thus crashes the server when valentine isn't installed.
line 218
Uncaught TypeError: Cannot call method 'abort' of undefined
The requests are going through as expected, but I get that error message.
I'll probably just add a typeof check there, but I wanted to bring it to your attention.
My AJAX request looks like the following:
var xhr = reqwest({
url: url,
data: options,
dataType: 'jsonp',
type: 'jsonp',
timeout: this.opts.timeout,
crossDomain: true,
success: function(resp) {
callback.success(resp);
},
error: function(resp) {
if (error_timeout) {
clearTimeout(error_timeout);
}
callback.error(resp);
}
});
Thanks,
Troy
As far as I can see JSONP support has been added in this pull request
but data
param is not added to query string
As mentioned in other requests, the XHR object/some kind of response/metadata object passed in to the success callback would be useful.
In the instance of a current project, we use reqwest for loading web pages into a container. We also do this when we submit forms. When the form is submitted, the backend then redirects to another page, which reqwest handles quite nicely. The only issue is that when we navigate/submit forms, we use the history API to update the URI. As we don't 'know' where reqwest was redirected to, the URI cannot be updated with the URI of the page we were redirected to.
In a brand new directory, running "ender build" with reqwest listed doesn't give any errors but fails to assemble any packages. ie, the only thing created is node_modules.
Eg...
$ ender build reqwest bonzo
Welcome to ENDER - The no-library library
installing packages: "ender-js reqwest bonzo"...
this can take a minute...
successfully finished installing packages
assembling packages...
$ ls
node_modules
Running the same build command without including reqwest works correctly resulting in ender.js and ender.min.js files.
Hi,
I need to manage manual uploads through ajax. With the HTML5 APIs we have two techniques : by FormData or by using the sendAsBinary() method of the XHR object. Some documentation:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest?redirectlocale=en-US&redirectslug=DOM%2FXMLHttpRequest%2FUsing_XMLHttpRequest#Submitting_forms_and_uploading_files
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/FormData/Using_FormData_Objects?redirectlocale=en-US&redirectslug=DOM%2FXMLHttpRequest%2FFormData%2FUsing_FormData_Objects
Which technique seems to be the "best" with reqwest? Can I handle this yet?
I humbly request that the version number start making it's way into the source for reqwest. It's becoming increasingly difficult to identify the version based on line number and/or file compare, if one doesn't name the containing directory or the file according to release version.
In jQuery one can assign a context to a ajax call, which comes in handy in some situations (eg when loading many assets at the same time)..
myObj = { foo: "bar" }
$.ajax({
url: "...",
context: myObj,
success: function(c) {
console.log(this.foo);
}
});
Would be nice to have this option in reqwest, too.
What do you think?
$("myform").serialize({type:'map'});
TypeError: Object # has no method 'concat'
see integrate function:
var args = (this && this.length > 0 ? this : []).concat(Array.prototype.slice.call(arguments, 0))
In the past, "this" would be an array, not it's an Ender object.
Al trough no actual samples for complete callback but it seems it should be there after looking at readyState function.
I wish you could explain the options in the readme file, the examples look okay but sometimes I dont know what they do.
Pretty much like mikeal/request is explained.
thanks
I'm trying to run tests before working on reqwest and I can't get tests to succeed. Is it my setup that isn't working?
opening tests at http://localhost:1234
writing file: ./node_modules/sink-test/src/sink.css./node_modules/sink-test/src/sink
Error: EBADF, Bad file descriptor './/node_modules/sink-test/src/sink.css./node_modules/sink-test/src/sink'
at Object.openSync (fs.js:221:18)
at Object.readFileSync (fs.js:112:15)
at /Users/pothibo/Develop/reqwest/make/tests.js:29:20
at /Users/pothibo/Develop/reqwest/node_modules/dispatch/lib/dispatch.js:67:26
at Array.some (native)
at Object.handle (/Users/pothibo/Develop/reqwest/node_modules/dispatch/lib/dispatch.js:63:22)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:203:15)
at Object.query [as handle] (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/middleware/query.js:38:5)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:203:15)
at HTTPServer.handle (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:216:3)
Error: Can't set headers after they are sent.
at ServerResponse.<anonymous> (http.js:527:11)
at ServerResponse.setHeader (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/patch.js:62:20)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:165:13)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:212:9)
at Object.query [as handle] (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/middleware/query.js:38:5)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:203:15)
at HTTPServer.handle (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:216:3)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1134:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
http.js:527
throw new Error("Can't set headers after they are sent.");
^
Error: Can't set headers after they are sent.
at ServerResponse.<anonymous> (http.js:527:11)
at ServerResponse.setHeader (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/patch.js:62:20)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:165:13)
at next (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:212:9)
at HTTPServer.handle (/Users/pothibo/Develop/reqwest/node_modules/connect/lib/http.js:216:3)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1134:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1029:22)
at Socket._onReadable (net.js:677:27)
npm ERR! [email protected] test: `node make/tests.js`
npm ERR! `sh "-c" "node make/tests.js"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is most likely a problem with the reqwest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node make/tests.js
npm ERR! You can get their info via:
npm ERR! npm owner ls reqwest
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Darwin 11.2.0
npm ERR! command "node" "/usr/local/bin/npm" "test"
npm ERR! cwd /Users/pothibo/Develop/reqwest
npm ERR! node -v v0.4.12
npm ERR! npm -v 1.0.94
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/pothibo/Develop/reqwest/npm-debug.log
npm not ok
in setType
(link), if the developer doesn't set a type
when using reqwest, it defaults to js
. I'm curious as to why it's that, instead of html
or json
?
The reason I ask is this tripped me up today and I kept getting an Unexpected token :
error until I specified the type I wanted to return was json. Just curious why it's js
in particular.
h5's.
Hi!
Seems there exist some compat issues preventing use of this $.ajax, at first glance:
Reqwest: method, type, headers, headers['Content-Type'], none, none
jQuery : type, dataType, none, contentType, onBeforeSend(), ?callback=
How'd you suggest to normalize?
TIA,
--Vladimir
With HTML5, the likelihood that a user would want to download binary data is a real possibility (audio, photo/video, etc).
There ought to be a way to get an ArrayBuffer in the success callback. This would require a base64->TypedArray conversion. This is a little platform dependent at the time, but it could be very useful (I would use it =D).
The default could be Uint8Array, but it could also be user-defined.
I was about to add this in, but I wasn't sure if this was too specific for reqwest.
For example, when I make a post request, it would be nice to be able to pass an object of values for the request. Similar to the way jQuery handles this.
It looks like right now I can pass in data, but it must be a string with key/values.
I'm not sure if this has been discussed before, but would it be possible to add some license information to the repo?
I think this would help to clarify if and under which conditions people are allowed to reuse and modify the code in other projects.
Thank you!
Seems like there's no XDomainRequest support in reqwest. CORS in IE8 is somewhat broken (can't use xhr, have to use XDomainRequest, can't send custom headers, etc...), but it's something that I need and I might extend reqwest to support it.
Not sure if this is something that you guys will want to support? If so, and if no forks exist yet with support for XDR, I can submit a pull request, if my changes work...
Had some issues with "req.xhr" in Express, after a little research with the help of Firebug and looking through the code for Reqwest I found that X-Requested-With is never set as a header. Why is this?
Ran into the issue described here http://www.nczonline.net/blog/2009/06/23/loading-javascript-without-blocking/ when testing with IE7 and IE8
Even stranger is that the final
readyState
isnβt alwayscomplete
. Sometimes,readyState
stops atloaded
without going on tocomplete
and sometimes it skips overloaded
altogether.
The solution appears to be as described -- interpreting either loaded
or complete
as a trigger for the onload()
callback at https://github.com/ded/reqwest/blob/master/reqwest.js#L92
The test suite is using .some, which isn't IE-compatible.
It would be nice if a cache parameter can be passed to an ajax request: if set to false, it will force requested pages not to be cached by the browser. Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL. (from jquery page http://api.jquery.com/jQuery.ajax/).
Thx
I'd like to be able to specify an options object to be passed to the constructor of the XHR object.
Specifically, I'd like to be able to pass the nonstandard options mozAnon and mozSystem to the XHR constructor, and it seems an anonymous option will be available in the future.
Pretty much directly from one of your README examples, I have this code which is not working as expected:
ajax({
url: url,
type: "jsonp"
//,success: function(){alert("success");}
})
// complete?
.then(function(data){
alert(data);
})
// failure?
.fail(function(){
alert("fail")
});
I have verified that the JSONP which comes back from the server is properly formed, and that it actually executes (if I insert an alert()
, it happens). Moreover, if I uncomment the success
line above, it will actually fire. But the then()
is never firing.
Any idea why?
@ded I appreciate your adding support for synchronous requests.
Unfortunately, the callbacks don't seem to fire when async
is set to false
.
I believe the handleReadyState
function is called within the send
call, which is before this.request
is set, and so this.request
is undefined inside the handler.
I fixed it locally by adding if (o.async === false) this.request = http
just before the http.send(data)
call, but it's not the most elegant approach.
The IE fix for onreadystatechange in not in the current npm verstion (0.6.2).
This is breaking also Ender.
Please update the package, thanks!
Scenario:
When specifying JSON as type in options object and returned data is not valid json.
Outcome:
Throws an uncatchable error.
A possible solution would be to try catch the JSON.parse and on catch pass an error to the error callback specified in the
options object?
When the the Content-Type
header of a request is set to application/json
shouldn't the request data be converted to a JSON string using JSON.stringify
?
Currently I'm sending my requests like this:
reqwest({
url: '/api/v1/user',
type: 'json',
method: 'post',
contentType: 'application/json',
processData: false,
data: JSON.stringify({
first_name: 'John',
last_name: 'Doe'
})
});
But it would be easier if I could do this:
reqwest({
url: '/api/v1/user',
type: 'json',
method: 'post',
contentType: 'application/json',
data: {
first_name: 'John',
last_name: 'Doe'
}
});
I'm getting a syntax error on line 198 of the unminified version that's currently up on Github (commit 48fe7e). The full error is:
Uncaught SyntaxError: Unexpected identifier
success reqwest.js:198
headers reqwest.js:53
Hey,
I'm psyched to switch to reqwest (and eliminate jQuery in my project), but one of the things I was depending on jquery-jsonp (the more-acceptable JSONP library for jQuery) for was having multiple JSONP requests with the same callback running in parallel - something that, it seems, reqwest can't handle yet.
I might be able to work on a patch for this - jquery-jsonp has just a bit of extra code for recording multiple scripts returning from JSONP-land, and returning the right values to the right things.
I am trying to use ajax to submit a form:
$.ajax({
url: '/settings',
method: 'put',
data: $('form').serialize()
});
But I am getting an error "Cannot call method 'getElementsByTagName' of undefined" in Chrome. Any ideas or am I missing something?
reqwest.serialize = function (form) {
var inputs = form[byTag]('input'),
selects = form[byTag]('select'),
texts = form[byTag]('textarea');
return (v(inputs).chain().toArray().map(serial).value().join('') +
v(selects).chain().toArray().map(serial).value().join('') +
v(texts).chain().toArray().map(serial).value().join('')).replace(/&$/, '');
};
I'd fork and fix but I don't know what 'v' is supposed to be...
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.