writing out a null in javascript

大城市里の小女人 提交于 2019-12-11 13:37:03

问题


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

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.

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

255 216 255 212 0 16 ...

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


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.


回答1:


What about base-64 encoding the data? You'll need to decode it of course.




回答2:


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


来源:https://stackoverflow.com/questions/1732149/writing-out-a-null-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!