简体   繁体   中英

Javascript code works on desktop but not on mobile

I have the following code for a web page that is supposed to upload an image, from camera or file system, and then convert it to a string before sending it off with as a JSON request.:

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

The code above will be called when an image is chosen. It will change a selected image to a string before sending it off in a JSON request. It should be able to run on a web browser on desktop or on mobile. It works perfectly on desktop. I can convert the image I upload to a string and send it off to my server no problem.

However when I do the same on my phone I get an error saying Error in processing request: undefined.

Without the Chrome debugger, which was a huge help, and things like Fiddler on the machine, is there any way to hunt down what might be going wrong? I dont really know how to attack this issue on the phone.

As per Jan's response to my question, the Chrome debugger for my Android phone worked perfectly. Solved my problem in no time.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM