【问题标题】:Add Javascript function return value to output将 Javascript 函数返回值添加到输出
【发布时间】:2014-10-14 19:00:00
【问题描述】:

我有以下代码:

var Faculty180API = {
    token: '1a88be52b9e9dd649998c3c1979b6b5c79cc160e',
    base_url: 'https://www.faculty180.com/api.php',
    account: 'DemoLinks',
    last_results: null,

    fetch: function(path, params, callback) {
        $.ajax((this.base_url + this.make_path(path)), {
            data: this.make_params(params),
            crossDomain: true,
            xhrFields: { withCredentials: true },
            success: callback,
            dataType: 'json',
            error: function(xhr) {
                if(xhr.status == 200) {
                    $('#results').text(xhr.responseText);
                }
                else {
                    $('#URL').text(Faculty180API.base_url . HERE);          
                    $('#results').text(xhr.status + ' - ' + xhr.statusText);  
                }
            }
        });
    },
    make_params: function(params){
        params['token'] = this.token;
        return $.param(params);
    },
}

在我写HERE 的行中,我想将Function(params) 返回的内容添加到输出中。我该怎么做?

【问题讨论】:

  • 你说的Function(params)是什么?你的意思是底部的make_params函数?

标签: javascript function output return-value


【解决方案1】:

尚未对此进行测试,但我认为您可以这样称呼它:

$('#URL').text(Faculty180API.base_url + Faculty180API.make_params( yourParams ) );

另请注意,我更改了您的 . (在 base_url 之后)到 +。点是 PHP 中的字符串连接;在 Javascript 中是 +

【讨论】:

  • 另外,make_params 函数后面有一个额外的逗号,应该删除。
猜你喜欢
  • 1970-01-01
  • 2018-08-27
  • 2017-08-19
  • 1970-01-01
  • 2023-03-20
  • 2020-10-24
  • 1970-01-01
  • 2014-11-17
  • 1970-01-01
相关资源
最近更新 更多