2011-11-04 68 views
0

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

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

    } 

ServiceProxy.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); 
      } 
     }); 
    } 
} 

enter image description here

由于

BB

+0

您使用萤火虫或类似的东西?你会得到什么错误? –

回答

0

Ĵ确保在最终的html文档中,要使用的脚本在用户脚本之上声明。无论是与外部包括:

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

或粗糙的脚本:

<script> used </script> 

<script> user </script> 
+0

因为我在Visual Studio文件中使用外部JS文件,所以不需要使用脚本标记。 – BumbleBee

相关问题