I'm expecting the following piece of code to execute the Ajax call. However, I see a 405 error which says
The requested resource does not support http method 'GET'.
If I use type = 'json' I get
The requested resource does not support http method 'JSON'.
Here is the relevant portion of my content script code
$(document).ready(function() {
var imgSrcArr = [];
$('img').each(function(e) {
var s = this.src;
imgSrcArr.push(s);
$.ajaxSetup({cache: false});
var formData = new FormData();
formData.append("apikey", "xxxxxxxxxxxxxxx");
formData.append("isOverlayRequired", false);
formData.append("url", s);
//console.log(formData);
//console.log($.support.cors);
$.ajax({
url: "https://api.ocr.space/parse/image",
data: {apikey: "xxxxxxxxxxxxxxx", url: s},
//method: 'GET',
dataType: 'json',
async: false,
cache: false,
contentType: "application/json; charset=utf-8",
processData: false,
type: 'GET',
crossDomain: true,
xhrFields: {
// The 'xhrFields' property sets additional fields on the XMLHttpRequest.
// This can be used to set the 'withCredentials' property.
// Set the value to 'true' if you'd like to pass cookies to the server.
// If this is enabled, your server must respond with the header
// 'Access-Control-Allow-Credentials: true'.
withCredentials: true
},
headers: {
// Set any custom headers here.
// If you set any non-simple headers, your server must include these
// headers in the 'Access-Control-Allow-Headers' response header.
},
success: function(ocrParsedResult, textStatus, jqXHR) {
//Get the parsed results, exit code and error message and details
var parsedResults = ocrParsedResult["ParsedResults"];
var ocrExitCode = ocrParsedResult["OCRExitCode"];
var isErroredOnProcessing = ocrParsedResult["IsErroredOnProcessing"];
var errorMessage = ocrParsedResult["ErrorMessage"];
var errorDetails = ocrParsedResult["ErrorDetails"];
var processingTimeInMilliseconds = ocrParsedResult["ProcessingTimeInMilliseconds"];
//If we have got parsed results, then loop over the results to do something
if (parsedResults!= null) {
//Loop through the parsed results
$.each(parsedResults, function (index, value) {
var exitCode = value["FileParseExitCode"];
var parsedText = value["ParsedText"];
var errorMessage = value["ParsedTextFileName"];
var errorDetails = value["ErrorDetails"];
var textOverlay = value["TextOverlay"];
var pageText = '';
switch (+exitCode) {
case 1:
pageText = parsedText;
break;
case 0:
case -10:
case -20:
case -30:
case -99:
default:
pageText += "Error: " + errorMessage;
break;
}
console.log(parsedText);
var bazExtract = extractEmails1(parsedText);
if(bazExtract !== null) {
extractEmails2(bazExtract);
}
});
}
},
error: function(err) {
console.log(err);
}
});
});
//console.log(imgSrcArr);
});
A note: Other sections of the content script code are running as expected but there's no Server response (in the developer console) to the Ajax request.
If this is a CORS issue, is there a workaround for this kind of an error? I tried a handful of answers to similar questions on SO but I'm unable to move forward with any of those.