N
N
Natalya Chobot2017-07-06 21:09:02
JavaScript
Natalya Chobot, 2017-07-06 21:09:02

How to add data to db.json using jQuery client side?

So I have a db.json file

{
  "tags": [
    {
      "idTag": 1,
      "nameTag": "fun"
    }
  ]
}

there is an index.html file
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
        <script>
            $.ajax({
                type: "POST",
                url: "http://localhost:3000/tags",
                data: {"idTag": 2, "nameTag": "title"}
            });
        </script>
    </head>
    <body>
    </body>
</html>

I start my json-server in cmd using json-server --watch db.json,
then I open my index.html file
, after that the following error is displayed in the console:
271b4cef5a124d4980719faffe17c6ca.JPG
and of course no data is added.
how to fix the error and what error so that the data is added?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Natalya Chobot, 2017-07-07
@nata-ponchik

The error was in this:
it was necessary to write like this:
data: {"id": 2, "nameTag": "title"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question