1

I am sending a ajax request with the following data. The data here is an object and I intend to send an object itself (not stringified JSON). But when I see the request in browser, the request payload is displayed as [object object] even though I am sending a project JS object.

let emailIdForAPICall = { "email": "[email protected]"};

$.ajax({
          type: 'POST',
           url: gigyaServlet,
           data: {    
             'profile': emailIdForAPICall,
           }
    })

Once the above API call is triggered, the payload looks like below - enter image description here

Tried using JSON.parse(JSON.stringify(emailIdForAPICall)) but it still did not work.

Whats worrying is, same type of request works a different site properly.

2 Answers 2

0
let emailIdForAPICall = {
    "email": "[email protected]"
};

$.ajax({
    type: 'POST',
    url: gigyaServlet,
    data: JSON.stringify({  //stringify your obj
        'profile': emailIdForAPICall,
    }),
    contentType: 'application/json',  // add contentType
})
Sign up to request clarification or add additional context in comments.

1 Comment

The data to be sent with request should be an object. I cannot stringify it. And the contentType is set as application/json
0

Ramya Shivu your request is from data or JSON. if JSON then please pass contentType: 'application/json',in header & if it is form data

let emailIdForAPICall = { "email": "[email protected]"};

 $.ajax({
              type: 'POST',
               url: gigyaServlet,
               data: JSON.stringify({  //stringify your obj
            'profile': emailIdForAPICall,
        })
        })

1 Comment

Hi, I have added content: application/json. and the requirement is not to stringify the object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.