Javascript代码可以在桌面上使用,但不能在手机上使用

Javascript code works on desktop but not on mobile

本文关键字:手机 但不能 桌面 代码 Javascript      更新时间:2023-09-26

我有一个网页的以下代码,该网页应该从相机或文件系统上传图像,然后将其转换为字符串,然后作为JSON请求发送

var fileToLoad = new Blob([images[0]], {
            type: 'image/tif'
        });+
    var fileReader = new FileReader();
    fileReader.onload = function(fileLoadedEvent) {
        var srcData = fileLoadedEvent.target.result; // <--- data: base64
        var divTest = document.getElementById("imgTest");
        var newImage = document.createElement('img');
        newImage.src = srcData;
        imageString = newImage.outerHTML;
        //<img src="data:image/tif;base64,SUkqAAgAAAATAP4ABAABAAAAAAAAAAABBAABAAAAsAQAAAEBBAABA…71sXFsbHw8F/BP6Hr9+JZlWf//+1UVYRmCIUOFbllbXhaaSzELdERERERERET8//////8/AAIg">
        imageString = imageString.substring(32, imageString.length-2); //The above returns a string for <img src.......>. So this line removes the html stuff to leave just the image string
        console.log(imageString);

            var testJSON =
            {
                "jobWithDocsInitialization": {
                "InputVariables": [{
                    "Id": "InputVar",
                    "Value": "Conor"
                }],
                "RuntimeDocumentCollection": [{
                    "Base64Data": null,
                    "Data": null,
                    "DeleteDocument": true,
                    "DocumentGroup": {
                        "Id": null,
                        "Name": "",
                        "Version": 0
                    },
                    "DocumentName": "",
                    "DocumentTypeId": null,
                    "FieldsToReturn": null,
                    "FilePath": null,
                    "FolderId": null,
                    "FolderTypeId": null,
                    "MimeType": null,
                    "PageDataList": [{
                        "Data": null,
                        "Base64Data": imageString,
                        "MimeType": "image/tiff",
                        "RuntimeFields": {}
                    }],
                    "PageImageDataCollection": null,
                    "ReturnAllFields": true,
                    "RuntimeFields": null
                }],
                "StartDate": null
                },
                "processIdentity": {
                    "Id": null,
                    "Name": "DriversLicRTTI",
                    "Version": 10
                },
                "sessionId": "C640521793431F4486D4EF1586672385",
                "variablesToReturn": {"id":"loopIndex"}
            };
            ajax.send(JSON.stringify(testJSON));
    }
    fileReader.readAsDataURL(fileToLoad);

当选择图像时,将调用上面的代码。在JSON请求中发送之前,它会将选定的图像更改为字符串。它应该能够在桌面或手机上的网络浏览器上运行。它在桌面上运行得很好。我可以将上传的图像转换为字符串并发送到我的服务器,没有问题。

然而,当我在手机上做同样的事情时,我会收到一个错误,说处理请求时出错:未定义。

如果没有Chrome调试器(这是一个巨大的帮助),以及机器上的Fiddler之类的东西,有什么方法可以找出可能出现的问题吗?我真的不知道如何在电话里解决这个问题。

根据Jan对我问题的回答,我的Android手机的Chrome调试器运行得很好。很快就解决了我的问题。

https://developer.chrome.com/devtools/docs/remote-debugging

相关文章: