0

this code:

$.ajax({
url: "https://blahblah.co/api/agentinbarcode",
method: "POST",
data: {
    agentId: 6,
    city:'-',
    barcodeSerial:'HID9904000015',
    lat:141,
    lon:256

},
success: function (response) {
    console.log(JSON.parse(response))
    
},
error: function (response) {
    console.log(response)
}
});

response diffrently from this:

var datttaaaa ={ barcodeSerial: 'HID9904000015',
                    lat:141,
                    lon: 256,
                    city:"-",
                    agentId:6}

fetch('https://blahblah.co/api/agentinbarcode', {
                method: 'POST',
                headers: {
                 'Content-Type': 'application/x-www-form-urlencoded',
                },
            body: JSON.stringify(datttaaaa),
        }).then((response) => response.json())
            .then((responseJson) => {
                console.log(responseJson);
           
            })
            .catch((error) => {
                
                console.error(error);
            });

the response of both must be 'this id has already been sent' which $.ajax perfectly does it and correct but the Fetch api returns "this id do not exist in the site"

are these two one and same? same URl same Data if it's not what is my problem?

noshad b.e
  • 114
  • 11
  • In fetch method, set the Content-Type header to application/json – esnezz Jun 27 '20 at 10:11
  • more info: https://stackoverflow.com/questions/9870523/differences-in-application-json-and-application-x-www-form-urlencoded – esnezz Jun 27 '20 at 10:13

0 Answers0