2011-11-04 1 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
J

반드시 최종 HTML 문서에서 사용되는 스크립트가 사용자 스크립트 위에 선언되어 있는지 확인하십시오. 어느 쪽의 외부는 다음과 같습니다

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

또는 거친 스크립트를 : 당신은 같은 방화범 또는 무언가를 사용하고

<script> used </script> 

<script> user </script> 
+0

Visual Studio 파일에서 외부 JS 파일을 사용하기 때문에 스크립트 태그를 사용할 필요가 없습니다. – BumbleBee