I have this problem
My Ajax request:
function test(){
const json = {"name" : {"name" : "test", "other" : 4} };
$.ajax({
type: "POST",
url: "http://localhost:8080/print.php",
data: {m:json, mm:"5"},
dataType: 'application/json; charset=utf-8',
cache: false,
success: function(neu){
console.log(neu.status);
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log(textStatus);
console.log(errorThrown);
}
}).fail( function( jqXHR, textStatus, errorThrown ) {
console.log(textStatus);
console.log(errorThrown);
});
}
My PHP (print.php)
<?php
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
$ticket = $_POST['m'];
// if remove this, print "ok" "ok" and i don't know why, never had problem with that
$connector = new NetworkPrintConnector("192.168.1.5",9100);
$printer = new Printer($connector);
//
$response['status'] = "ok";
echo json_encode($response);
?>
When i make test(); on console
Return : "ok" 1 time , no errors (always good)
But when i make test();test(); at the same time on console...
Return : "ok" only 1 time, when it should be "ok" "ok" without errors
ok
parsererror
index.php:8408 SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at n.parseJSON (jquery.js?v=270:4:5309)
at vc (jquery.js?v=270:4:7397)
at x (jquery.js?v=270:4:10802)
at XMLHttpRequest.<anonymous> (jquery.js?v=270:4:14767)
index.php:8411 parsererror
index.php:8412 SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at n.parseJSON (jquery.js?v=270:4:5309)
at vc (jquery.js?v=270:4:7397)
at x (jquery.js?v=270:4:10802)
at XMLHttpRequest.<anonymous> (jquery.js?v=270:4:14767)
jquery.js is just jquery 2.1.4 library.
I tried:
Quit dataType: 'application/json; charset=utf-8', and put dataType: 'json',
Without dataType,
With and Without : header('Content-type: application/json'); on PHP..