How to submit this ajax request?

Asked

Viewed 120 times

-1

Look at this print:

inserir a descrição da imagem aqui

Actually up there is a request ajax already sent, and I want to learn how to write this, look how I did and it’s not working:

$.ajax({ 

    url:'linkdeumsitequaisquer.com.br',
    type:'post',
    data:{questionId: 1, questionKey: "IDENTITY_SAFETYQUESTION_1},
    dataType:'json',
    success:function(res) {
        alert(res);

   }






});

I feel that something is missing, because there is this 0 and 1 there , in case must be vector within the date right? Something like this I don’t know much about theory, there’s another thing that people talk about object I also don’t know objects relates to javascript not understanding this, I know object is class car { } no PHP other than that I don’t know.

But the bottom line is: - How to write the request AJAX How was it sent in the image? - What is object in javascript this business of manipulation of JSON and such

  • It’s not working because it’s missing " ... questionKey: "IDENTITY_SAFETYQUESTION_1} <~ is not closing.

  • Javascript, Everything is an object., rs or almost everything. I found even your example of car class there. Incidentally it’s funny that the people who learn OOP always start with class carro or class pessoa kkkk.

  • I don’t understand friends please exemplify

  • Have you checked the missing quotes as pointed out in the first comment? What appears in the browser console?

  • Tries [{questionId: 1, questionKey: "IDENTITY_SAFETYQUESTION_1"}], you can not pass only the object, but rather a array of objects, so it does not show the indices

1 answer

3


How to write the AJAX request as it was sent in the image?

Your code has two errors, the first is not closing the quotes, and the second is not passing an array, so it is not equal to the image, to have the result you are looking for, your code should look like this:

$.ajax({ 
    url:'linkdeumsitequaisquer.com.br',
    type:'post',
    data: [{questionId: 1, questionKey: "IDENTITY_SAFETYQUESTION_1"}],
    dataType:'json',
    success:function(res) {
        alert(res);
   }
});

The way you did, you could only send one object at a time, you can send several by inserting each one into [] and separating each by ,

Ex.:

data: [{questionId: 1, questionKey: "IDENTITY_SAFETYQUESTION_1"},
       {questionId: 3, questionKey: "IDENTITY_SAFETYQUESTION_3"}]

What is object in javascript

I think that link answers that question:
How prototypes work in Javascript?

this JSON manipulation business

And that also answers the last question:
What is JSON? What is it for and how it works?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.