{"id":25470155,"url":"https://github.com/thinkphp/jsonp","last_synced_at":"2025-11-04T18:30:30.065Z","repository":{"id":2944027,"uuid":"3957149","full_name":"thinkphp/JSONP","owner":"thinkphp","description":"A standalone lightweight JSONP JavaScript Library without dependencies that creates a JSON request using script tag injection and handles callbacks for you.","archived":false,"fork":false,"pushed_at":"2012-04-11T17:07:04.000Z","size":104,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T14:54:26.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://thinkphp.ro/apps/js-hacks/JSONP/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thinkphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-07T10:39:26.000Z","updated_at":"2017-09-17T06:31:35.000Z","dependencies_parsed_at":"2022-09-04T12:02:08.608Z","dependency_job_id":null,"html_url":"https://github.com/thinkphp/JSONP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2FJSONP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2FJSONP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2FJSONP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2FJSONP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkphp","download_url":"https://codeload.github.com/thinkphp/JSONP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239437233,"owners_count":19638451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-18T08:32:10.066Z","updated_at":"2025-11-04T18:30:30.019Z","avatar_url":"https://github.com/thinkphp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSONP\n=====\n\nJSONP or JSON with padding is a complement to the base JavaScript Object Notation JSON data format. It provides a method to\nrequest data from a server in a different domain. CORS can be used as a modern alternative to the JSONP pattern.\n\nSyntax:\n\n      new Jsonp(url, callback).fetch() \n\n         OR\n\n      new jsonp.fetch(url, callback)\n\n         OR\n\n      JSONP.get(url, params, callback)  \n\n         OR\n\n      JSONP.init({callbackName: 'jsoncallback'}) \n\n      JSONP.get(url, params, callback);\n\nHow to use:\n-----------\n\n         #Example-1\n         var username = 'yelf',\n\n         endpoint = 'http://query.yahooapis.com/v1/public/yql?q=',\n\n         yql = 'use \"http://thinkphp.ro/apps/lastfm/YQL-open-data-table/recentlastfm.xml\" as lastfm;select * from lastfm where username=\"'+ username +'\" and api_key=\"2993c6e15c91a2890c2f11fa95673067\"',\n\n         url = endpoint + encodeURIComponent(yql) + '\u0026format=json\u0026callback=?'\n \n         function callback(data) {\n\n                  document.getElementById('result').innerHTML = data.query.results.result;\n         } \n    \n         new Jsonp(url,callback).fetch();\n\n         #Example-2\n         var tpl = \"\u003cli\u003e\u003ca href='http://twitter.com/{from_user}'\u003e{from_user}\u003c/a\u003e {text}\u003cspan\u003e{created_at}\u003c/span\u003e\u003c/li\u003e\",\n\n         urltwitter = 'http://search.twitter.com/search.json?q=mootools\u0026rpp=5\u0026callback=?';\n\n         new Jsonp(urltwitter, function(data){\n\n               var result = data.results, \n\n               out = '\u003cul\u003e'\n                \n               for(var i in result) {\n\n                   out += template(tpl,result[i])\n               } \n               out += '\u003c/ul\u003e'\n\n              document.getElementById('result-twitter').innerHTML = out \n\n         }).fetch();\n\n  \n         #example-3\n         var url = 'http://search.twitter.com/search.json';\n\n         JSONP.get(url, {q: 'mootools', rpp: 10}, function(data){\n\n                  //do stuff with data\n         })\n       \n        #example-4\n        var urltwitter = 'http://search.twitter.com/search.json?q=mootools\u0026rpp=5\u0026callback=?'\n\n        jsonp.fetch(urltwitter, function(data){\n\n               var result = data.results, \n\n               out = '\u003cul\u003e'\n                \n               for(var i in result) {\n\n                   out += template(tpl,result[i])\n               } \n               out += '\u003c/ul\u003e'\n\n              document.getElementById('result-twitter').innerHTML = out \n        })\n\n        #example-5\n        //Get flickr photos search\n        var tpl = \"\u003cli\u003e\u003ca href='http://www.flickr.com/photos/{owner}/{id}' target='_blank'\u003e\u003cimg src='http://farm{farm}.static.flickr.com/{server}/{id}_{secret}.jpg' alt='{title}' width='75' height='75'/\u003e\u003c/a\u003e\u003c/li\u003e\",\n            url = 'http://api.flickr.com/services/rest/';\n\n        //Set Callback Name\n        JSONP.init({callbackName: 'jsoncallback'})\n\n        JSONP.get(url, \n\n                  {api_key: 'e407090ddb7d7c7c36e0a0474289ec74',\n                   per_page: 20, \n                   page: 1, \n                   text: 'beach kudos', \n                   has_geo: true, \n                   method: 'flickr.photos.search', \n                   format: 'json'},\n\n                   function(data) {\n\n                      var photos = data.photos.photo,\n                          n = photos.length,\n                          out = '\u003cul\u003e';\n\n                      for(var i=0; i\u003cn; i++) {\n\n                          out += template(tpl,photos[i])\n                      }  \n\n                      out += '\u003c/ul\u003e';\n\n                      $('container').innerHTML = out;  \n                   })          \n\n        //we can make multiple requests\n        JSONP.get(url, \n\n                  {api_key: 'e407090ddb7d7c7c36e0a0474289ec74',\n                   per_page: 20, \n                   page: 1, \n                   text: 'san francisco', \n                   has_geo: true, \n                   method: 'flickr.photos.search', \n                   format: 'json'},\n\n                   function(data) {\n\n                      var photos = data.photos.photo,\n                          n = photos.length,\n                          out = '\u003cul\u003e';\n\n                      for(var i=0; i\u003cn; i++) {\n\n                          out += template(tpl,photos[i])\n                      }  \n\n                      out += '\u003c/ul\u003e';\n\n                      $('container').innerHTML = out;  \n                   })          \n\n**Happy Requesting!**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkphp%2Fjsonp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkphp%2Fjsonp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkphp%2Fjsonp/lists"}