Comments (10)
hmm... the before send can be added.
?callback=
is a JSONP thing. in which case i'd probably recommend using $.getScript
$.getScript('http://example.com/?callback=jazz');
of course we can work in some magic in $script.js to wrap it in a nice callback so you can just do this:
$.getScript('foo.js', {
handlerName: function () {
// done
}
});
from reqwest.
Personally, I find reqwest interface clearer. The most confusing is type
option which has completely different meanings in both flavors.
What if expose reqwest interface under different alias (say $.Ajax
), and make $.ajax
be a wrapper, which should take jQuery options, reduce them to reqwest options and delegate to $.Ajax
, printing a warning to the console?
Not very clear, but should help initial transition, and constant warnings may eventually make people to use reqwest ;)
from reqwest.
Hi! Any progress in coping with this issue? They just consider it a stopper: jashkenas/backbone#322 (comment)
from reqwest.
I agree with @dvv in principle. I like reqwest's syntax better too.
Perhaps instead of a wrapper, there could be a compat mode: reqwest.compat('jQuery')
or something that's set once.
This would bloat reqwest a little, but a few bytes never hurt anyone =D
from reqwest.
I came out with this to patch Spine.js:
if (reqwest) {
$ajax = function(params) {
var error, success;
params.method = params.type.toLowerCase();
params.type = params.dataType;
delete params.dataType;
params.headers = {
'Content-Type': params.contentType
};
if (params.success) {
success = params.success;
params.success = function(data) {
return success(data, "success", this);
};
}
if (params.error) {
error = params.error;
}
params.error = function(data) {
return error(data, "error", this);
};
return reqwest(params);
};
} else if (jQuery) {
$ajax = $.ajax;
}
I am sure it's buggy and handles only one use case.
But it's quite similar on what RightJS does with his jquerysh plugin.
from reqwest.
i'm starting to like the idea of calling compat('jquery')
which invokes a bridge. i'll see if i can have a play with that.
from reqwest.
would a patch for a 'dataType' option (per jQuery, basically would allow sending Content-Type: application/json instead of application/x-www-form-urlencoded) be welcomed? This is an adoption-blocker for me.
from reqwest.
You can provide a custom Content-Type
as it is, without a dataType
option. This is roughly what a JSON call can look like with Reqwest:
$.ajax({
url: '/happyPlace',
method: 'post',
type: 'json',
data: JSON.stringify(happyData),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
success: onSuccess,
error: onError
});
Reqwest has sensible defaults for Accept
and Content-Type
but they aren't enforced if you provide your own.
from reqwest.
Thanks, but I'm (also) working with a library that expects things to work like jQuery and take a 'dataType' option instead of specifying headers.
from reqwest.
Eh, I can override it just fine with something like:
oldajax = $.ajax;
$.ender({ ajax: function(options) {
if (options.dataType === 'json') {
if (! options.headers) { options.headers = {}; }
options.headers['Content-Type'] = 'application/json';
}
oldajax(options)
}});
It's not ideal but it works.
from reqwest.
Related Issues (20)
- Setting contentType to application/json leads to session cookie not being sent HOT 1
- Setting content-type to 'application/json' on POST seems to be broken HOT 2
- context undefined when using webpack HOT 8
- reqwest 404 Request Method:OPTIONS
- Uncaught TypeError: Cannot read property 'responseText' of undefined
- if ajax return empty string ,the success function first param type will become "XMLHttpRequest" HOT 1
- How to abort a request? HOT 1
- Unable to send multipart/form-data request HOT 2
- Incorrect handling of response data
- reqwest promise with Nock HOT 1
- in IOS/Android webview, CORS, reqwest run error
- cache
- when I use reqwest post file,there is error: nested exception is java.lang.NullPointerException
- No err was throwed when network disconnected
- Ability to disable TLS at compile time? HOT 1
- CORS error when trying to get google geocoding HOT 4
- not support more than 16 integer data in response data
- how can i get response head HOT 3
- Type settings jsonp, jsonpCallback and jsonpCallbackName are not added, there will be default callback? HOT 1
- greenhouse HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reqwest.