pmiranda
pmiranda

Reputation: 8420

String Parameter in jquery ajax POST

The Curl of the API says that this is the correct format:

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "2018062703,2018062703" "http://XX.XX.XX/api/my_url"

This API need parameters like this:

enter image description here

I'm trying to send them with this code:

var data = "2018062703,2018062703";
$.ajax({
    type: 'POST',
    data: data,
    url: 'my/api/url',
    dataType: 'json',
    success: etc...

But I get a 404 not found. In the console of Chrome I got this:

What I'm doing wrong? In the web of the API when I put the parameters as a string "2018062703,2018062703" it works.

enter image description here

Upvotes: 0

Views: 454

Answers (1)

Pierre-Loup Pagniez
Pierre-Loup Pagniez

Reputation: 3761

Your data parameter in your AJAX call is invalid. It should look like this:

data: { filtro: data }

As it is now, you're trying to call your API with a parameter named 2018062703,2018062703 which has no value.

Upvotes: 2

Related Questions