2016-11-15 61 views
1

我們試圖使用cldr/globalize,不幸的是,頁面加載過程中會觸發錯誤。E_INVALID_PAR_TYPE在頁面加載過程中被觸發(cldr,globalize)

調試代碼不會在所有幫助,我想不通其中輸入磁場產生

你需要進一步的信息的問題?你需要更多的代碼嗎?只要讓我知道


E_INVALID_PAR_TYPE: {"expected":"Plain Object","name":"json","value":null}

的JavaScript,負載CLDR數據,區域設置爲 'EN'

$(document).ready(function() { 
    // http://stackoverflow.com/questions/35863853/using-jquery-globalize-with-mvc-5 
    // download json files on https://github.com/unicode-cldr?page=2 
    // how to setup globalize, cldr and json data: http://johnnyreilly.github.io/globalize-so-what-cha-want 

    var locale = 'en'; // TODO: manage the localization based on user preferences (browser) 

    // http://stackoverflow.com/questions/32586551/what-is-the-best-way-to-handle-validation-with-different-culture 
    $.when(
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/likelySubtags.json"), 
     $.getJSON("/Scripts/plugins/cldr-numbers-full-30.0.2/main/" + locale + "/numbers.json"), 
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/numberingSystems.json"), 
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/plurals.json"), 
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/ordinals.json"), 
     $.getJSON("/Scripts/plugins/cldr-numbers-full-30.0.2/main/" + locale + "/currencies.json"), 
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/currencyData.json"), 
     $.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/ca-gregorian.json"), 
     $.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/timeZoneNames.json"), 
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/timeData.json"), 
     $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/weekData.json"), 
     $.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/dateFields.json"), 
     $.getJSON("/Scripts/plugins/cldr-units-full-30.0.2/main/" + locale + "/units.json"), 
     console.log("JSONs loaded") 
    ).then(function() { 
     console.log("start slicing"); 
     return [].slice.apply(arguments, [0]).map(function (result) { 
      console.log("slicing done"); 
      return (typeof result === 'undefined' ? null : result[0]); 
     }); 
     }).then(Globalize.load).then(function() { 
     Globalize.locale(locale); 
     console.log("Locale set to " + locale); 
     }).then(console.log("LOADED EVERYTHING")); 


}); 

HTML,加載JavaScript的

<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>StratEx | Project management</title> 
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE"> 
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css"> 
    <link href="/Scripts/plugins/jquery-ui-1.11.4/jquery-ui.css" rel="stylesheet"> 

    <link href="/Content/font-awesome/css/font-awesome.css" rel="stylesheet"> 

    <link href="/Content/bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet"> 

    <link href="/Content/animate.css" rel="stylesheet"> 
    <link href="/Content/style.css" rel="stylesheet"> 

    <link href="/Content/themes/redmond/jquery-ui-1.10.3.custom.min.css" rel="stylesheet"> 

    <script type="application/javascript" async="" defer="" src="https://by2.uservoice.com/t2/ID/web/ID/track.js?_=TIMESTAMP&amp;s=1&amp;c=__uvSessionData0&amp;d=HASH"></script> 
    <script type="text/javascript" async="" src="//widget.uservoice.com/CODE.js"></script><script async="" src="//www.google-analytics.com/analytics.js"></script> 
    <script 
    src="/Scripts/jquery-2.2.1.js"></script> 

    <script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr.js"></script> 
    <script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr/event.js"></script> 
    <script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr/supplemental.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/number.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/plural.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/message.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/currency.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/date.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/relative-time.js"></script> 
    <script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/unit.js"></script> 
    <script src="/Scripts/plugins/jquery-validation-1.15.1/dist/jquery.validate.js"></script> 
    <script src="/Scripts/plugins/jquery-validation-unobtrusive-3.2.6/jquery.validate.unobtrusive.js"></script> 
    <script src="/Scripts/plugins/jquery-ajax-unobtrusive-3.2.4/jquery.unobtrusive-ajax.js"></script> 
    <script src="/Scripts/plugins/jquery-validation-globalize-1.0.0/jquery.validate.globalize.js"></script> 

    <script src="/Scripts/plugins/jquery-ui-1.11.4/jquery-ui.js"></script> 

    <script src="/Content/bootstrap-3.3.7/js/bootstrap.js"></script> 

</head> 

回答

0

問題來自console.log追加arguments裏面的一個項目undefined

我被修正的bug:

  1. 刪除, console.log("JSONs loaded")
  2. 修訂return (typeof result === 'undefined' ? null : result[0]);通過return result[0];
1

我認爲這與你的切片有關...有一種情況下,你返回null,這是Globalize.load抱怨的(它期望一個普通的對象,例如,{},而是它變得null)。

+0

我已經找到了問題,我不得不刪除線,' console.log(「JSONs加載」)'但問題依然存在,我一直觸發這個錯誤「JavaScript運行時錯誤: E_INVALID_PAR_TYPE:「value」參數無效(空)。一個預期的字符串「 – Abdelkrim

+1

對於哪個url,你的回答是'undefined'?我想如果你使用'return(typeof result ==='undefined'?{}:result [0]);'你會繞過這個問題,這個至少有用於斷言在那裏發生的錯誤,然後你可以恢復並找到哪個url不返回json。 –

相關問題