Coder Social home page Coder Social logo

reqwest's People

Contributors

afc163 avatar apfelbox avatar bartsidee avatar beatgammit avatar bryanjswift avatar c0 avatar dabio avatar davidmfoley avatar ded avatar drzhbe avatar igorw avatar imdom avatar javisantana avatar jrf0110 avatar keronsen avatar lastw avatar magnars avatar meltingice avatar oliverjash avatar pdehaan avatar philip-wernersbach avatar philipjrose avatar popomore avatar rvagg avatar satazor avatar tarekw avatar voxpelli avatar willwhite avatar yeonhoyoon avatar yiminghe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reqwest's Issues

Add context: parameter

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?

Why isn't X-Requested-With set as a request header?

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?

Be able to pass an object of data

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.

Add a cache parameter

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

JSONP broken in IE8

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.

Value of readyState in IE

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 always complete. Sometimes, readyState stops at loaded without going on to complete and sometimes it skips over loaded 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

Readme information on benefits

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.

Encode request data as JSON when Content-Type is set to application/json

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

The error() function should be given sensible arguments

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).

Put in option for synchronous AJAX calls

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

JSONP + Promise form, not working?

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?

Missing trailing semicolon

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.

serialize() doesn't work with ender

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?

Supporting multiple requests with the same JSONP callback

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.

Uncaught SyntaxError: Unexpected identifier

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

serialize calls 'v', which is not defined.

  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...

jQuery compat

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

serialize fails w/ ender

$("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.

Add license information

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!

Most recent commit breaks stuff

I added a commit note here:

b4a007c

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.

Populate ajax request from Form node

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.

Remove eval() calls

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!

Assembling ender.js package fails

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.

Bump npm package to 0.6.4

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!

request headers

Hi!

How do i set request headers, in particular, Content-Type:

TIA,
--Vladimir

Adding Reqwest breaks minified Ender build

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).

XDomainRequest / IE8

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...

Use git tags for version management and Bower integration

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?

.gitmodules missing

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.

Uncaught TypeError: Cannot call method 'abort' of undefined on line 218

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

Complete callback never called

Al trough no actual samples for complete callback but it seems it should be there after looking at readyState function.

Why is the default type 'js'?

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.

Binary data on GET?

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.

Add support for default options

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!

Tests aren't working?

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

success, error, complete callbacks do not fire when "async" is "false"

@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.

Return URI if Reqwest is redirected

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.

Please start putting version number in reqwest.js and reqwest.min.js

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.

FormData and sendAsBinary support

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.