Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
PLEASE REMOVE THIS QUESTION
I'm using JavaScript to try and retrieve the list of courses and am receiving a jQuery parse error when using $.getJSON. I have attached my code for your review.
I modified the access_token to protect the innocent 🙂 I also verified that the JSON being returned is in fact valid.
Thank you in advance for your assistance.
I'm trying to use the API from JavaScript as well. I am trying to use an jquery ajax call:
function getCourses(){
$.ajax
({
type: "GET",
url: "https://canvas.instructure.com/api/v1/courses",
// beforeSend: function (xhr) {
// xhr.setRequestHeader ("Authorization", "XXXX");
// },
headers: {
"Authorization": "XXXXXX",
"Access-Control-Allow-Origin": "*"},
dataType: 'json',
async: false,
success: function (){
console.log(data);
}
});
}
I get a cross domain errors.
It would be really helpful to have an example of how to get API calls working from client side JavaScript.
I would guess you should play around with jsonp instead of json for datatype in your javascript if the cross domain errors are persistent. There's lots of documentation online about it. But I could be wrong.
Here is how I'm using jsonp:
I'm trying to GET an Assignment
$.ajax({
type: "GET", // Type of request to be send
url: canvasapi, // url+token to which the request is sent
contentType: "application/json; charset=utf-8",
dataType: "jsonp", // type of data
success: function(data, status, jqXHR)
{
console.log( "success status: "+status );
console.log( "success data: "+data );
console.log( "success xhr text: "+jqXHR.responseText );
},
jsonp: false, // should use Callback below
jsonpCallback: function(data)
{
//var asgndata = JSON.parse(data);
//console.log( "jsonp asgndata: "+asgndata );
console.log( "jsonp data: "+data );// undefined - parsererror in returned data
},
error: function (jqXHR, status)
{
console.log( "ERR status: "+status );
console.log( "ERR xhr text: "+jqXHR.responseText );
}
});
It makes it past the CORS cross domain
But I'm getting a parser error so it data is undefined
This is the SAME exact error I am getting.
I tried a different API call to see if it caused an error.
It did.
I've added a new question that may help us get some answers.
I do have the API's working in PHP. Just not in JS.
I learned to cURL today. Much better.
Curl is cool indeed!
Hi @belgort ,
I am going through having a look at some of the early days in the Canvas Developers group, and checking in to see if older enquiries have been answered. I also noticed there hasn’t been any discussion on this question in quite some time.
I am wondering, were you ever able to resolve this with the assistance provided? I am hoping I can assume that it is well and truly resolved by now, but if not, please let us know and we can certainly have another look. Alternatively, if have some insights you may be able to share for others that would be awesome too!
I will mark this as assumed answered for the time being, however, by all means please let us know if you still have an outstanding question and we will take a peek!
Cheers,
Stuart
Stuart, not quite sure but you can close it 🙂
Thanks so much for the reply @belgort !
Cheers,
Stuart
To participate in the Instructure Community, you need to sign up or log in:
Sign In