简体   繁体   中英

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?

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"); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM