我想通过transcrypt代码获取文件。通常这是通过XMLHttpRequest完成的。在Javascript脚本中,新构造函数用于此目的。我如何进行transcrypt呢?这是我无法使用的代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def read_file():
xmlhttp=XMLHttpRequest()
xmlhttp.open('GET', "https://raw.githubusercontent.com/bunkahle/Transcrypt-Examples/master/README.md", False);
xmlhttp.send()
console.log(xmlhttp.responseText)
和html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="__javascript__/read_file.js"></script>
<title>Read File</title>
</head>
<body>
<main>
<h1>Read a file!</h1>
<p id="p1" class="para1">Read a file!</p>
<button id="button1" onclick="read_file.read_file()">Click for retrieving text file</button><br><br>
<p id="demo"></p>
</main>
</body>
</html>
答案 0 :(得分:1)
您可以使用 (e.Data as System.Windows.DataObject).GetFormats(false);
{string[4]}
[0]: "DragContext"
[1]: "DragImageBits"
[2]: "chromium/x-renderer-taint"
[3]: "FileDrop"
(e.Data as System.Windows.DataObject).GetData("DragContext");
'(e.Data as System.Windows.DataObject).GetData("DragContext")' threw an exception of type 'System.Runtime.InteropServices.COMException'
Data: {System.Collections.ListDictionaryInternal}
ErrorCode: -2147221404
HResult: -2147221404
HelpLink: null
InnerException: null
Message: "Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))"
Source: "System"
StackTrace: " at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)\r\n at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)\r\n at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)\r\n at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)\r\n at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)\r\n at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)\r\n at System.Windows.DataObject.GetData(String format, Boolean autoConvert)\r\n at System.Windows.DataObject.GetData(String format)"
TargetSite: {Void GetData(System.Runtime.InteropServices.ComTypes.FORMATETC ByRef, System.Runtime.InteropServices.ComTypes.STGMEDIUM ByRef)}
(e.Data as System.Windows.DataObject).GetData("DragImageBits");
{System.IO.MemoryStream}
CanRead: true
CanSeek: true
CanTimeout: false
CanWrite: true
Capacity: 87144
Length: 87144
Position: 0
ReadTimeout: '((System.IO.Stream)(e.Data as System.Windows.DataObject).GetData("DragImageBits")).ReadTimeout' threw an exception of type 'System.InvalidOperationException'
WriteTimeout: '((System.IO.Stream)(e.Data as System.Windows.DataObject).GetData("DragImageBits")).WriteTimeout' threw an exception of type 'System.InvalidOperationException'
(e.Data as System.Windows.DataObject).GetData("chromium/x-renderer-taint");
{System.IO.MemoryStream}
CanRead: true
CanSeek: true
CanTimeout: false
CanWrite: true
Capacity: 1
Length: 1
Position: 0
ReadTimeout: '((System.IO.Stream)(e.Data as System.Windows.DataObject).GetData("chromium/x-renderer-taint")).ReadTimeout' threw an exception of type 'System.InvalidOperationException'
WriteTimeout: '((System.IO.Stream)(e.Data as System.Windows.DataObject).GetData("chromium/x-renderer-taint")).WriteTimeout' threw an exception of type 'System.InvalidOperationException'
(e.Data as System.Windows.DataObject).GetData("FileDrop");
'(e.Data as System.Windows.DataObject).GetData("FileDrop")' threw an exception of type 'System.Runtime.InteropServices.COMException'
Data: {System.Collections.ListDictionaryInternal}
ErrorCode: -2147221404
HResult: -2147221404
HelpLink: null
InnerException: null
Message: "Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))"
Source: "System"
StackTrace: " at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)\r\n at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)\r\n at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)\r\n at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)\r\n at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)\r\n at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)\r\n at System.Windows.DataObject.GetData(String format, Boolean autoConvert)\r\n at System.Windows.DataObject.GetData(String format)"
TargetSite: {Void GetData(System.Runtime.InteropServices.ComTypes.FORMATETC ByRef, System.Runtime.InteropServices.ComTypes.STGMEDIUM ByRef)}
函数创建本机JavaScript对象:
(注意,对于实例化Python / Transcrypt类,不需要这样做)
__new__
有关这方面的更多信息,请访问: