0

在我的 Visual Studio 中,我有一个名为 Scripts 的文件夹,我试图从另一个外部 JS 文件调用一个外部 JS 文件。我无法让它工作。

jquery.fileupload-ui.js

 function GetAsgnInfo() {

        $.getScript("Scripts/ServiceProxy.js", function () {
              invoke("GetAsgnInfo",{ id: $("#IAsgnId").val() }, fnSuccess, onPageError);
           });

        function fnSuccess(data) {

        //    alert(typeof (data));
       //     alert(data);
            var newData = (data.hasOwnProperty("d") ? data.d : data)
            if (!jQuery.isEmptyObject(newData)) {
                $("span[id *= LUploadedCount]").text(data[0].UploadedCount);
           }
        }
        function onPageError(error) {
            alert("An error occurred:\r\n" + error.Message);
        }

    }

服务代理.js

this.ServiceProxy = function (serviceUrl) {
    var _I = this;
    this.serviceUrl = serviceUrl;
    this.isWcf = false;
    this.timeout = 10000;
    this.contentType = "application/json";

    this.invoke = function (method, params, callback, errorHandler) {

        var jsonData = _I.isWcf ? JSON.stringifyWcf(params) : JSON.stringify(params);

        // Service endpoint URL        
        var url = _I.serviceUrl + method;

        $.ajax({
            url: url,
            data: jsonData,
            type: "POST",
            contentType: _I.contentType,
            timeout: _I.timeout,
            dataType: "serviceproxy",  // custom type to avoid double parse
            dataFilter: function (jsonString, type) {
                if (type == "serviceproxy") {
                    // Use json library so we can fix up dates        
                    var res = JSON.parseWithDate(jsonString);
                    if (res && res.hasOwnProperty("d"))
                        res = res.d;
                    return res;
                }
                return jsonString;
            },
            success: function (result) {
                if (callback)
                    callback(result);
            },

            success: function (data) {
                var newData = (data.hasOwnProperty("d") ? data.d : data)
                callback(newData);
              },
            error: function (xhr, status) {
                var err = null;
                if (xhr.readyState == 4) {
                    var res = xhr.responseText;
                    if (res && res.charAt(0) == '{' && status != "parsererror")
                        var err = JSON.parse(res);
                    if (!err) {
                        if (xhr.status && xhr.status != 200)
                            err = new CallbackException(xhr.status + " " + xhr.statusText);
                        else {
                            if (status == "parsererror")
                                status = "Unable to parse JSON response.";
                            else if (status == "timeout")
                                status = "Request timed out.";
                            else if (status == "error")
                                status = "Unknown error";
                            err = new CallbackException("Callback Error: " + status);
                        }
                        err.detail = res;
                    }
                }
                if (!err)
                    err = new CallbackException("Callback Error: " + status);

                if (errorHandler)
                    errorHandler(err, _I, xhr);
            }
        });
    }
}

在此处输入图像描述

提前致谢

BB

4

1 回答 1

0

只需确保在最终的 html 文档中,要使用的脚本声明在用户脚本之上。要么带有外部包括:

<script src="..."></script>

或粗略的脚本:

<script> used </script>

<script> user </script>
于 2011-11-04T18:56:01.883 回答