Max Tamer-Mahoney
Max Tamer-Mahoney

Reputation: 11

Why won't the return value print from the jQuery $.post function?

First, let's start with the code.

chrome.tabs.getSelected(null, function(tab) {
    tabURL = tab.url;
    $.post("http://s.mxtm.me/yourls-api.php",
        { signature: "XXXXXXXXXX", 
          action: "shorturl", 
          url: tabURL, 
          format: "simple" 
        },
        function(data) { 
            $("body").append(data);
        });

I'm working on a little Chrome extension as a client for YOURLS, and I'm using the jQuery $.post function to interact with the YOURLS API.

Under function(data) { I'm attempting to print the return from my POST. I've tried appending, I've tried alerting, I've tried document.writing, but nothing works. Does anyone have any idea of what is wrong?

Upvotes: 0

Views: 414

Answers (1)

Strelok
Strelok

Reputation: 51461

That usually means that the ajax call is failing, add an error callback to see what's wrong:

$.post(
    "http://s.mxtm.me/yourls-api.php", 
    { signature: "XXXXXXXXXX", action: "shorturl", url: tabURL, format: "simple" },
    function(data) {   $("body").append(data); }
).error(function(xhr,error,ex) { alert("error"); });

Upvotes: 0

Related Questions