0

I have 2 objects generated by sqlite execution:

var info_update = {
id: 270,
cancelados: 2,
concluidos: 2,
total: 914
}

var participantes = [
    {id: "10",
     nome: "Antonio",
     idade: "4",
     ativo: 1,
     msg: "Backorder"
     },
    {id: "11",
     nome: "Carlos",
     idade: "1",
     ativo: 1,
     msg: "Flagged"
    }
]

For send the object I use this method on service:

var headers = {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        };
    return $http({
        method: "POST",
        url: "remote_url.com/action",
        data: {info_update: info_update, participantes: participantes},
        headers : headers
    })

What's the problem?

The parameter info_update it's sent to server, but the parameter participantes it's send empty, as appears in the attached image

I need send ALL data for serve. How i do it?

  • 1
    Try changing the content type to application/json but the participantes in the image looks like an empty object. Maybe from the server side, are you expecting an array or an object? – Vivz Jul 07 '17 at 04:36
  • @Vivz, I change to application/json, but its still empty :(... any else suggestion? – Roque Junior Jul 07 '17 at 04:47
  • 1
    What is your backend expecting participantes to be an array or an object? – Vivz Jul 07 '17 at 04:49
  • My problem isn't on backend, it's on frontend. I can't get the object 'participantes' to be sent as a parameter in the request. – Roque Junior Jul 07 '17 at 04:55
  • Can you just remove Content-Type header and give a try? or use "application/json" – Sujith Jul 07 '17 at 05:00
  • @Sujith gives the following error: XMLHttpRequest can not load http://remote_url.com/action. Response to preflight request does not pass access control check: In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost: 8100' is therefore not allowed access. – Roque Junior Jul 07 '17 at 05:08
  • This is a different issue. Not the one which you were facing earlier. https://stackoverflow.com/questions/39613831/how-to-solve-asp-net-web-api-cors-preflight-issue-when-using-put-and-delete-requ – Sujith Jul 07 '17 at 05:11
  • 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' with this header were you able to call the API? what was shown in the network tools of your browser? – Sujith Jul 07 '17 at 05:15
  • I do not think I'm being clear enough. I'm having trouble passing the object as a request parameter. The object is mounted correctly and I can see it on the console, but when I try to send it by the request it just will not go. This is my Header Form Data: {"info_update":{"id":"270","cancelados":2,"concluidos":2,"total":915},"participantes":{}}: – Roque Junior Jul 07 '17 at 05:23

1 Answers1

0

Your participantes is not object its array try changing it to object using .map function

sam
  • 688
  • 1
  • 12
  • 35