Why dataType: "text" doesn't bypass cors like "jsonp"
Situation:
With the script below to get text string from a small hardware device over wifi.
The device is configured as a wifi AP & does not respond to browser request, it just updates its web data every second. I can see the data string with ip address in web page(refresh = new data) & a script tag will receive as valid data. <script type="text/javascript" src="
http://192.168.4.1"> </script>
The text string is structured as multi line JS variables & is valid json.
Problem is I need to use type: "jsonp" so I don't get cors blocked but it then parses the response that for some reason is not conforming to json (even tho the data from device is valid json
I have yet to find a way to view what is actually being parsed as the Console Response Payload shows empty.
I don't care too much if the response is modified when it is assigned to my final variable as I can "parse" it / error check in JS.
- <script>
var RetStr // enable access to data outside ajax
//-----------------------
$.ajax({
url: "http://192.168.4.1/",
dataType: "jsonp", // <-- dataType: "text", gives cors error (tried "jsonp text", also)
// process response
success: function( response ) {
retVal1 = "Response data = " + response
console.log(retVal);
document.getElementById('varString').innerHTML = retVal1;
// RetStr = responsetext //???
},
error: function( response,err ) {
errVal1 = "Error data = " + response.status
errVal2 = "Error type = " + err
console.log(errVal1 + " , " + errVal2);
document.getElementById('varString').innerHTML = errVal1 + " , " + errVal2;
}
});
//-----------------------
</script>
The above is working to the point where I get error 200 & parsererror.
I have seen some example of side stepping the json parse but I can't apply it to my example above. Long time VB programmer, just a few weeks JS.
Console: