Skip to content

Loading…

One small and one essential fix #22

Open
wants to merge 2 commits into from

3 participants

@rootnot

Look at notes

@rootnot

Small fix.

@rootnot

Previous version generated: somefunction(){return {somejson}}

This should be somefunction({somejson});

@Marak
Owner

Are you sure about that? I'm pretty sure I tested this a few times in the browser. How are you testing your JSONP requests?

Yes I have tested it with this fragment of code:

_makeRequest: function(url, params, cb)
{
var cbUID = this._makeUID();
var sc = document.createElement('script');
var pa = [];
for (var p in params)
pa.push(p + '=' + encodeURIComponent(params[p]));
pa.push('callback=' + cbUID);
window[cbUID] = function(obj) {
document.body.removeChild(sc);
delete window[cbUID];
if (cb instanceof Function)
cb(obj);
};
sc.src = url + '?' + pa.join('&');
document.body.appendChild(sc);
},
_makeUID:function()
{
return 'f' + (Math.random() * (1 << 30)).toString(16).replace('.', '');
}

Feel free to debug: http://nodetest.metashop.pl/service/clientapi/test.html

@baub

JSONP was not working for me. Using this fix from rootnot made it work.

I'd suggest you pull this patch Marak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 21, 2011
  1. @rootnot

    Fixed bug in JSONPWRAP

    rootnot committed
  2. @rootnot

    Edited lib/view.js via GitHub

    rootnot committed
Showing with 2 additions and 4 deletions.
  1. +1 −3 lib/createRouter.js
  2. +1 −1 lib/view.js
View
4 lib/createRouter.js
@@ -276,7 +276,5 @@ var createMetaRoutes = exports.createMetaRoutes = function (module, routes){
}
var JSONPWRAP = exports.JSONPWRAP = function(namespace, data) {
- return 'function ' + namespace + '() {\
- return "' + data + '"\
- }';
+ return namespace + '(' + data + ')';
};
View
2 lib/view.js
@@ -82,7 +82,7 @@ var renderRoutes = exports.renderRoutes = function( format, name, items, templat
// form
html += ('<div class="form">');
- html += ('<form method="get" action="' + items.endpoint + '/' + method + '" + target="' + method + '-output">');
+ html += ('<form method="get" action="' + items.endpoint + '/' + method + '" target="' + method + '-output">');
for (var arg in s)
{
html += ('<div class="field">');
Something went wrong with that request. Please try again.