views:

51

answers:

1

Ok,

I'm trying to use jQuery $.post with the PasteBin API to create a PasteBin page and grab the URL (which the API says it returns). Here is my code so far:

$('#send_code').click(function(){
    $.post('http://pastebin.com/api_public.php', 
            { paste_name: $('#paste_name').val(), paste_code: $('#paste_code').val() },
            function(data){
                alert(data);
            });
}

The above script creates the page just fine (I can find them on PasteBin). However, all that is returned is an empty string. I've tried using this same API with php and cURL, and I'm able to retrieve the URL just fine. Can anyone see if I'm doing something wrong? Thanks!

+2  A: 

Browser cross-domain security policy does not allow you to make client-side requests to other domains, unless they offer the API specifically in a format designed to get around such restrictions, such as JSONP.

It looks like you're out of luck. You will have to send the request to your own server, and send the request to Pastebin on the server side.

Matchu
Ah, here's a 'duh' moment. I appreciate your response. Now I'm using jQuery to post to a local file, which then uses cURL to post to the PasteBin API and return the result, like you suggested.
John K