PUT/DELETE with jquery ajax js

380 views
Skip to first unread message

cucko

unread,
Apr 12, 2011, 4:31:43 AM4/12/11
to SoundCloudAPI
Has anyone succeeded to put/delete favorite with javascript.
I'm using jquery.sc.api.js, there are method like put/delete defined,
but in console i getting only GET method.

I've make same changes in jquery.sc.api.js, where i manualy set the
ajax type, and dataType, but still no success.
If dataType='json' throws an errror Request header field X-Requested-
With is not allowed by Access-Control-Allow-Headers.
If dataType='jsonp' throws 401, unauthorized. But in the script the
headers are set up with oauth Token.

In every case i'm trying with logged in user with OAuth on SC.

Any ideas ?

Thanks. Cucko

Matas Petrikas

unread,
Apr 12, 2011, 5:02:02 AM4/12/11
to soundc...@googlegroups.com
hi Cucko,

did you try out POST? if it works, you could do the request method override via _method param or via X-HTTP-Method-Override header:

the jquery.sc.api.js was created mainly as a showcase for the oauth client flow, so if you have any relevant patches add a pull request, so we can merge it back in.

greets,
Matas


--
You received this message because you are subscribed to the Google Groups "SoundCloudAPI" group.
To post to this group, send email to soundc...@googlegroups.com.
To unsubscribe from this group, send email to soundcloudap...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/soundcloudapi?hl=en.




--
Matas Petrikas



http://soundcloud.com/matas


Matas Petrikas

unread,
Apr 15, 2011, 3:56:09 AM4/15/11
to soundc...@googlegroups.com
hi Cuco,

the thing is, that you don't need jsonp to access our API, we have
CORS support, that allows real cross-domain AJAX communication.
could you post an example of your request as gist
https://gist.github.com? you can replace the consumerId and
accessToken values with random strings.

greets,
Matas

cucko

unread,
Apr 12, 2011, 7:20:11 AM4/12/11
to SoundCloudAPI
If i remove dataType: jsonp it still returns
Request header field X-Requested-With is not allowed by Access-Control-
Allow-Headers. for POST.

With dataType:jsonp, it only fires GET automaticly, so no way to do
POST with jsonp.

Is there some workaround like GET call with auth header and param
method, to https://api.soundcloud.com/me/favorites/{TrackID}.json?_method=PUT&key=...
so the favoriting will be possible with JavaScript Jquery Ajax. I
really don't want to include other programming languages in my app
except JS. :)

Also can be useful if you put Favorite button on Embed widget player
with authToken. So the users will be able to favorite tracks without
opening another/popup window.
The app is here http://favoritecloudplayer.net78.net/ .

Thanks, Cucko

http://soundcloud.com/cucko

cucko

unread,
Apr 16, 2011, 6:27:36 AM4/16/11
to SoundCloudAPI
I've find the issue.

The problem was on my dev server which does not allow anything but
"GET" ajax request for some reason.
On hosting server now it works fine.

If somebody need the JQuery code, here it is.
url = "https://api.soundcloud.com" + "/users/" + scUserID + "/
favorites/" + trackid + ".json?_method=" + method + "&oauth_token=" +
userToken;
$.ajax({
'url': url,
'type': method,
'dataType': 'json',
'crossDomain' : true,
'success': function(response) {

},
'error': function(a, b, c) {

}
});

i'm not sure if method is needed in both places as param and in ajax
settings. but it works ok..
now logged user can favorite the track from the results grid. yeeeee

thanks matas.

cucko

On Apr 12, 1:20 pm, cucko <dcu...@gmail.com> wrote:
> If i remove dataType: jsonp it still returns
> Request header field X-Requested-With is not allowed by Access-Control-
> Allow-Headers. for POST.
>
> With dataType:jsonp, it only fires GET automaticly, so no way to do
> POST with jsonp.
>
> Is there some workaround like GET call with auth header and param
> method, tohttps://api.soundcloud.com/me/favorites/{TrackID}.json?_method=PUT&key=...
Reply all
Reply to author
Forward
0 new messages