Return $.get data in a function using jQuery

前端 未结 6 1334
臣服心动
臣服心动 2020-11-29 20:29

I\'m trying to call a function that contains jQuery code. I want this function to return the results of the jQuery statement. It is not working, and I\'m trying to figure ou

6条回答
  •  执念已碎
    2020-11-29 21:13

    Looks like you want synchronous request: How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

    Or, you may want to pass callback to your function:

    function showGetResult (name, callback) {
      var scriptURL = "somefile.php?name=" + name;
      return $.get(scriptURL, {}, callback);
    }
    
    showGetResult("John", function(data){ alert(data); });
    

提交回复
热议问题