写出在JavaScript空 [英] writing out a null in javascript

查看:126
本文介绍了写出在JavaScript空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是在跟进这一个:<一href=\"http://stackoverflow.com/questions/1712211/write-binary-data-using-javascript-on-the-server\">write在服务器使用JavaScript二进制数据。

This question is in follow up to this one: write binary data using JavaScript on the server.

与仅仅使用的Response.Write 来写入字符串存在的问题是,该字符串包含的JavaScript识别为字符串的结尾空字符。

The problem there with just using Response.Write to write the string is that the string contains a null character which JavaScript recognizes as the end of the string.

我试图用写开始的字符串如下(以字符codeS写到这里)

The string I'm trying to write starts with the following (written here in character codes)

255 216 255 212 0 16 ...

JavaScript就只能输出这里的前4个字符,因为它承认5日作为一个字符串结束。有没有解决这个办法吗?

JavaScript will only output the first 4 characters here, because it recognizes the 5th as a string terminator. Is there any way around this?


我要指出,我真的要写出二进制空...这个输出是PDF格式,所以我不能改变输出格式。

I should note that I really do have to write out the binary null... the output of this is pdf, so I can't change the output format.

推荐答案

您应该能够直接传​​递一个空物体进入写入功能,并把它输出相同为空字符串,应该没有运行时错误。正是如此如下code将没有返回到屏幕上:

You should be able to pass a null object directly into the Write function and have it output the same as an empty string, there should be no runtime errors. Thusly the following code will return nothing to the screen:

protected void Page_Load(object sender, EventArgs e)
{
    string str = null;
    Response.ContentType = "text/plain";
    Response.Write(str);
    Response.End();
}

这篇关于写出在JavaScript空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆