Theme Installer: Use JSONP for api.wordpress.org requests.

fixes #27639.


git-svn-id: https://develop.svn.wordpress.org/trunk@27961 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2014-04-05 20:27:56 +00:00
parent 1ff1343a82
commit ba9e3d2bc3

View File

@ -317,34 +317,25 @@ themes.Collection = Backbone.Collection.extend({
request: {} request: {}
}, },
// Send Ajax POST request to api.wordpress.org/themes // Send request to api.wordpress.org/themes
apiCall: function( request, paginated ) { apiCall: function( request, paginated ) {
// Ajax request to .org API // Send tags (and fields) as comma-separated to keep the JSONP query string short.
return $.ajax({ if ( request.tag && _.isArray( request.tag ) ) {
url: 'https://api.wordpress.org/themes/info/1.1/?action=query_themes', request.tag = request.tag.join( ',' );
}
// We want JSON data // JSONP request to .org API
dataType: 'json', return $.ajax({
type: 'POST', url: 'https://api.wordpress.org/themes/info/1.1/?callback=?',
crossDomain: true, dataType: 'jsonp',
// Request data // Request data
data: { data: {
action: 'query_themes', action: 'query_themes',
request: _.extend({ request: _.extend({
per_page: 72, per_page: 72,
fields: { fields: 'description,tested,requires,rating,downloaded,downloadLink,last_updated,homepage,num_ratings'
description: true,
tested: true,
requires: true,
rating: true,
downloaded: true,
downloadLink: true,
last_updated: true,
homepage: true,
num_ratings: true
}
}, request) }, request)
}, },