converting curl in jquery ajax request
vectraboyv6 opened this issue · 3 comments
vectraboyv6 commented
Hi after reading this github ive thought about writing a webpage based add on for my "magic mirror"
how ever im stuck straight away with the curl -> jquery convertion
<script> $.ajax({ contentType: 'application/json;charset=utf-8', type: 'POST', dataType: 'json', //async: true, url: 'https://www.services.renault-ze.com/api/user/login', data: { username: "stuart.brown@gmail.com", password: "Pass99" }, dataType: "json", error: function (data) { console.log(data); }, success: function (data) { console.log(data); } }); </script>this returns 400 bad request . on inpection the @ is being turned into %40 ????
im not a master programmer so now stuck
edent commented
Could you show us some of your code? Not your password - obviously - but need to see a little more.
The percent encoding looks right though.
vectraboyv6 commented
$.ajax({
contentType: 'application/json;charset=utf-8',
type: 'POST',
dataType: 'json',
//async: true,
url: 'https://www.services.renault-ze.com/api/user/login',
data: {
username: "Example@gmail.com",
password: "Pass99"
},
dataType: "json",
error: function (data) {
console.log(data);
},
success: function (data) {
console.log(data);
}
});
thats all ive got so far :(
edent commented
I'm not an expert with jQuery - but it looks like you need to "stringify" your data. See http://stackoverflow.com/questions/12693947/jquery-ajax-how-to-send-json-instead-of-querystring