jaubourg / jquery-jsonp Goto Github PK
View Code? Open in Web Editor NEWjquery jsonp plugin
License: MIT License
jquery jsonp plugin
License: MIT License
API documentation
Tips&Tracks
Other links
Hi,
I would be helpful to add a LICENSE.txt file in the root directory.
Thank you!
Gary
hey,
could you brief on the callback and callbackParameter option.
do callback relates to jsonpCallback in Jquery ajax jsonp request?
Hi.
If I use plain $.ajax() and pass a data object with some undefined attribute (something like
$.ajax({
dataType: 'jsonp',
url: '...',
data: {
foo: 'bar',
baz: undefined // <- that
}
})
they doesn't get propagated as query parameters.
Instead, using $.jsonp() I see "?...&attribute=undefined&..." in the url.
It's possible to ignore undefined attribute?
Perhaps there is a way already but it would be great if I could execute code after all requests using this were completed, similar to how I would using jQuery's Global Ajax Event Handlers.
This returns a syntax error
$.jsonp({
url : 'http://cvrapi.dk/api?search=test&country=dk',
success : function(json){
console.log('success')
},
error : function(){
console.log('err')
}
});
This works
$.ajax({
type : 'GET',
dataType : 'jsonp',
url : '//cvrapi.dk/api?search=test&country=dk',
success : function(res){
}
});
Hello,
This code looks awesome! Thanks so much for sharing it with the rest of us. :)
I just have a few questions:
$.jsonp()
over jQuery's $.getJSON()
and/or $.ajax()
?page
caching? I can't think of a situation where I'd want to use page
caching over browser
caching.Thanks!!!!
Cheers,
Micky
...
I set 3 seconds for requests running. If time passes and the response is not received, callback set to complete will be call and a message will be shown.
The message will be "error occur, please try again." I want to make an anchor for "try again", when someone click it, the same request will be sent again. But I haven't found such an API. Is there any ways to do it?
I've been sweating over this for a while now, and I can't seem to find a solution. I have asked on Stackoverflow, but haven't gotten an answer, so I'm hoping I can get an answer here.
I'm calling jsonp
the standard way:
window.ongoing_request = $.jsonp({
url: theurl,
timeout : 5000,
success: function (json, textStatus, xOptions) {
process_data(json);
},
error: function (xOptions, textStatus) {
if (textStatus == "timeout") {
toggle_timeout_error(true);
}
//what about 404 error?
}
});
I want to be able to detect what error has happened in the error
callback, but so far I'm only able to see if a timeout error has occurred, by checking the value of the textStatus
argument. But if it's a 404 error, or any other HTTP error, the textStatus
just equals "error", and I can't find a way of getting the HTTP error code from the xOptions object.
How do I get the HTTP error code in case an HTTP error has happened?
We had some issues embedding our code in other peoples sites where other 3rd party code was also modifying the head element. Changing the following fixed this:
// Append main script
head[STR_INSERT_BEFORE](script, firstChild);
// Append trailing script if needed
scriptAfter && head[STR_INSERT_BEFORE](scriptAfter, firstChild);
to
// Append main script
head[STR_INSERT_BEFORE](script, head.firstChild);
// Append trailing script if needed
scriptAfter && head[STR_INSERT_BEFORE](scriptAfter, head.firstChild);
I believe this is because firstchild no longer exists once the other script has modified the head dom element and so when firstchild is used later down the script it throws a dom element not found exception
When calling $.jsonp in IE10 on Windows 8 the function always returns the error() function. Breakpointing notifyError doesn't indicate the issue is related to a timeout and no other details are really given other than the second arg is "error"
Hello, thank you for the good job, I found this library pretty useful but I need to make POST requests, not GET. Is it possible to add a 'type' option like in $.ajax to tell if we should perform a GET or POST?
Thanks, regards
Maurizio
I'm new to javascript (mostly a back-end developer). I'm trying to send over the contents of an array using jquery 2.1.1 and jquery.jsonp 2.4.0.
My code snippet that I'm trying to use:
var checkedBoxes = {
ids: []
};
$("input[name='ids']:checked").each(function () {
checkedBoxes.ids.push(this.value);
});
$.jsonp({
// bunches of stuff (URL, callback, etc.)
data: checkedBoxes
});
Unfortunately this fails. When looking at the Wireshark trace, I see the following:
GET /Provider/People?ids%5B%5D=1&ids%5B%5D=4&callback=people&_1412031156507=
So the information is there, and the callback name I specify is also there. What's tripping things up is that there appears to be extraneous [] after every ids (%5B%5D).
What am I doing wrong?
I can build the query string by hand, but I was hoping to use the object syntax.
Thanks for any pointers.
Mark
/mde/
I'd want to make a POST request. Will it be possible in the future ?
jQuery Plugin Registry: http://plugins.jquery.com/
Thanks!
$.jsonp({
url: 'http://d.yimg.com/autoc.finance.yahoo.com/autoc',
callback: 'YAHOO.Finance.SymbolSuggest.ssCallback',
data: {
query: query
},
success: function(data) {
return console.log('success');
},
error: function(d, msg) {
return console.log(msg);
}
});
Any idea?
Your plugin is magical, and does things I didn't think was possible with the nature of jsonp. I've looked at the source code and I guess it's just beyond me what's going on (even though I'm pretty decent with javascript). Any chance you could give an overview of how it actually achieves things like error handling that vanilla jQuery doesn't do? (You might consider putting this in the readme too)
..
I’m working on a pet project this weekend and I’ve been banging my head against this problem and wonder if I could run it by you?
So it’s an extension for safari/chrome, and one thing it does is hits the Wikipedia api. To circumvent the cross domain policy stuff, I'm using a JSONP request, hit a url with that and parse the object that comes back.
var wikipedia_api = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=revisions&rvprop=content&exchars=750&prop=extracts";
$.jsonp({
"url": wikipedia_api,
callback: "?",
"data": {
titles: “Algebra"
},
"success": function(data) {
console.log(data)
},
"error": function(d,msg) {
console.log(d);
}
As I understand it, callback=? will trigger a jsonp request instead of a traditional json request. When I run this, there’s an error in the console that line 1 of the wikipedia API.php has failed with the error 'SyntaxError: Unexpected token ‘:’ — When I inspect that file, I actually can see the object trying to get returned:
{"warnings":{"main":{"*":"Unrecognized parameters: 'rvprop', '_1390673688561'"}},"query":{"pages":{"18716923":{"pageid":18716923,"ns":0,"title":"Algebra","extract":"<p><b>Algebra</b> (from Arabic <i>al-jebr</i> meaning \"reunion of broken parts\") is one of the broad parts of mathematics, together with number theory, geometry and analysis. Algebra arose from the idea that one can perform operations of arithmetic with non-numerical mathematical objects. At the beginning of algebra, and at elementary level, these objects are variables representing either numbers that are not yet known (<i>unknowns</i>) or unspecified numbers (<i>indeterminates</i> or <i>parameters</i>). This allows one to state and prove properties that are true no matter which specific numbers are involved. More generally, these objects may have various basic properties, and, presently, algebra is divided in several subareas which include</p>..."}}}}
The ‘query’ part of that object is actually coming back from the Wikipedia API. So something with the callback? I'm having no luck here.
I want to capture header status code like 200, 400
When a request is aborted with the xOptions object that is returned, the error callback should be invoked if present.
Thx for this. Handling errors in jsonp otherwise a big problem.
Using the following script
<script type="text/javascript" src="query-1.7.2.min.js"></script>
<script type="text/javascript" src="jquery.jsonp-2.4.0.min.js"></script>
<script>
url="http://api.cosm.com/v2/feeds/68131/datastreams/GenerationEnergy.json?api_key=ArMTcMNGVOSUp8ntlhmO6_UIHZ6SAKwxVEtWQXhzNElTbz0g&start=2012-09-23T23:00:00Z&end=2012-09-24T10:00:00Z&interval=300&per_page=1000&timezone=London";
console.log("url",url);
$.jsonp({
cache:false,
dataFilter: function (json) {
console.log("data",json);
return json;
},
complete: function () {
console.log("complete");
},
error: function (xOptions,textStatus) {
console.log("error",JSON.stringify(xOptions),textStatus);
},
success: function (json,textStatus,xOptions) {
console.log("success",json,textStatus,xOptions);
},
url: url
});
</script>
I get an error "SyntaxError: Unexpected token ':'" when the data being returns is correct json, as verified with jsonlint.com
Any suggestions or could this be a bug?
BTW. it also seems that the dataFilter callback was not fired.
Thx. Paul
$.jsonp({
url : $this.getCheckStatusUrl(),
data : {},
xhrFields: {withCredentials: false},
callback : "callbackAction",
success : function(json) {}
});
I add like this, but it does not work, is anything goes wrong?
Hello,
First of all, thank you for a such module. It is a good alternative to the native jquery jsonp dataType cause it allows to catch HTTP errors.
But, this lib seams not to be able to catch more than juste "there is an error"
It would be great to have the HTTP status code and the HTTP status message as parameters of the "error" callback.
Do you think it's doable ?
For example: if my jsonp server returns
HTTP/1.1 500 Internal Server Error
I'd like to have:
error: function (opt, httpStatusCode, httpStatusMessage) {
console.log(httpStatusCode); // 500
console.log(httpStatusMessage); // Internal Server Error
}
regards,
Stéphane
Is there a way to stop listening for the success, error, etc events? If there isn't a way, it would be great if one could be made.
For example, it would be great to do the following (or some other way) in order to stop listening to the success event:
var
url: sURL2Use,
cache: false,
success: onMainFeedLoad,
error: onMainFeedError
});
$jsonp.removeListener("success");
Is it possible to get something like If-Modified like the $.ajax has? The Android devices are not able to bust the browser cache. Since the data calls are server cached, the default browser cache busting cannot be used. Currently this works in most of the browsers and iOS browser as well with the parameters of
cache:true,
pageCache : false
First of all thank you for contributing such a useful library, it really helps me a lot.
I was wondering whether it's possible to get more information for the error callback. Because sometimes I want to treat errors differently according to their types. A 500 Internal Server Error
is surely different with the Connection Refused
or Connection Timeout
, for the former I might want to contact the website administrator, and for the later I might just ignore them.
Is that possible now? Is it technically possible?
And would you consider implementing it in the future if it's technically possible?
Hello
is it possible to add a queue feature such as that when given qname parameter. multiple request with same qname will be served one by one in queue order.
there is already a nice plugin for that check this url
https://code.google.com/p/jquery-ajaxq/
but i wish it could be combined here so that we can use both queue and jquery-jsonp features
Thanks
I have been looking, but I can't find a change log. I'm trying to determine if this library will make use of ie's xdomainrequest object. I am using a slightly out of date version of jquery-jsonp and I have some users ( but not all ) users that are having their requests blocked. I have both jquery and the 3rd party server set to use CORS headers, but IE ignores them.
Has this been dealt with in a newer version? Or do I need to detect ie 9 myself and separate style of request?
Thanks
Hello, thank you for the good job!
I'm trying to send request with a multivalued parameter as it is described in your documentation:
$.jsonp({
"url" : myUrl,
callbackParameter : 'callback',
data : {
foo : ['bar1', 'bar2']
},
success : function(data) {
...
The request is well appended with multiple http parameters, but foo
is changed in foo[]
:
http://....?foo%5B%5D=bar1&foo%5B%5D=bar2&callback=_jqjsp&_1372862109097=
did I miss something?
Thanks
plugin version is 2.4.0
jquery version is 1.8.3
When proper JSON and not proper JSONP is returned, then we must ensure that "&callback=?" is added at the end of the URL or else the following error will occur:
"Uncaught SyntaxError: Unexpected token :"
Contrarily to
We at VersionEye are working hard to keep up the quality of the bower's registry.
We just finished our initial analysis of the quality of the Bower.io registry:
7530 - registered packages, 224 of them doesnt exists anymore;
We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).
Sadly, your library jaubourg/jquery-jsonp
is one of them.
Can you spare 15 minutes to help us to make Bower better?
Just add a new file bower.json
and change attributes.
{
"name": "jaubourg/jquery-jsonp",
"version": "1.0.0",
"main": "path/to/main.css",
"description": "please add it",
"license": "Eclipse",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
"<dependency_name>": "<semantic_version>",
"<dependency_name>": "<Local_folder>",
"<dependency_name>": "<package>"
},
"devDependencies": {
"<test-framework-name>": "<version>"
}
}
Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.
NB! Please validate your bower.json with jsonlint before commiting your updates.
Thank you!
Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!
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.