/ Published in: JavaScript
Using .join('&') because with long strings it will take less processing and memory to build an array than to build a string.
Expand |
Embed | Plain Text
function doJsonp(url, data, callback) { data.callback = callback; var get = []; for (var field in data) { get.push(encodeURIComponent(field) + '=' + encodeURIComponent(data[field])); } var script = document.createElement('script'); script.setAttribute('type', 'text/javascript'); script.setAttribute('src', url + '?' + get.join('&')); document.head.appendChild(script); }
You need to login to post a comment.
