“错误CS1012:字符文字中的字符过多”

时间:2013-11-22 05:37:27

标签: javascript asp.net

我有一个带滑块的照片库的JavaScript代码,但是有一个问题:

 var partnum = "<%Response.Write(Request.QueryString["partno"]); %>";

    // check if the file is exiset -- it's running in bar() function -- run on servers and local host. 
    function UrlExists(url) {
        var http = new XMLHttpRequest();
        http.open('GET', url, false);
        http.send();
        return http.status != 404;
    }

    // push images paths to array 
    function bar() {
        var exict = 0;
        var counter = 0; //counter of array's index
        for (var i = 1 ; exict < 30; i++) {
            // if there isn't .jpg or .gif
            if (!UrlExists("/assets/catalog/parts/" + partnum + "_" + i + ".jpg") && !UrlExists("/assets/catalog/parts/" + partnum + "_" + i + ".gif")) {
                exict = exict + 1;
            }
            // if there is .jpg
            if (UrlExists("/assets/catalog/parts/" + partnum + "_" + i + ".jpg") && !UrlExists("/assets/catalog/parts/" + partnum + "_" + i + ".gif")) {
                arrOfImgs.push("/assets/catalog/parts/" + partnum + "_" + i + ".jpg");
                counter = counter + 1;
            }
            // if there is .gif 
            if (UrlExists("/assets/catalog/parts/" + partnum + "_" + i + ".gif") && !UrlExists("/assets/catalog/parts/" + partnum + "_" + i + ".jpg")) {
                arrOfImgs.push("/assets/catalog/parts/" + partnum + "_" + i + ".gif");
                gifIndex.push(i);
                counter = counter + 1;
            }
        }
}

但它不起作用,所以我试图改变var partnum
 var partnum = <%= new JavaScriptSerializer().Serialize(Request.QueryString['partno']) %>;

但我收到错误:“错误CS1012:字符文字中的字符过多”。我仍然不确定这是否是问题,因为我的原始代码确实有效(您可以在访问网站.baumhaus时看到初始产品图片已加载并点击产品系列,然后点击任何产品,您将看到动作 - 一旦它试图渲染缩略图就消失了。)

1 个答案:

答案 0 :(得分:0)

怎么样

var partnum = '<%= Request.QueryString["partno"] %>'";