edent / Renault-Zoe-API

A basic API for getting information about your Renault Zoe Electric Vehicle.
92 stars 24 forks source link

converting curl in jquery ajax request #2

Closed vectraboyv6 closed 6 years ago

vectraboyv6 commented 7 years ago

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

this returns 400 bad request . on inpection the @ is being turned into %40 ???? im not a master programmer so now stuck

edent commented 7 years ago

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 7 years ago
$.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 7 years ago

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