I've been trying to get a POST request from an API, and I'm not having that much luck in pushing it through. I'm wondering if it's because one of the parameters I'm passing is an array of objects. Been trying to get this to work for a few hours with no luck.
This post function requires two parameters, userId and classId.
//here's the api I'm calling, obviously not the actual URL
let apisource = www.exampleapi.com
//this is the class
let classId = 12345;
//these are students in the class
let userArray = [{
"name": "user1",
"userId": 101
}, {
"name": "user2",
"userId": 102
}]
I'm writing a function that takes this userArray and matches it up to a class that contains the userIds.
Here's my API call so far:
function getStudents(classId, userArray) {
$.post(apisource) + "classes"), {
userId: userArray.userId,
classId: classId
}, function(data, status) {
console.log("students in class loaded)
}
}
Nothing ever loads. Anyone have any suggestions or pointers for something I might be doing wrong?
getStudentsfunction?)afterapisourceto the end of your functionhttp://3. it also requires support for CORS requests