This is an extension of my previous question... it was resolved but a new issue has come up after getting past that.

Here's the code I'm currently using:

var clientContext = new SP.ClientContext("http://sitecollection/sites/Dev");
var oList = clientContext.get_web().get_lists().getByTitle('User List');
var item = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(item);

oListItem.set_item('Last Name', 'toby');


clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

This fails on the callback (I think). See the below screenshot:

enter image description here

I am unsure where I am going wrong here... on my previous question, someome had mentioned using app context, something like this:

var context = new SP.ClientContext.get_current();
var hostContext = new SP.AppContextSite(context, hostUrl);
var hostWeb = hostContext.get_web();

But I can't call load on hostWeb... can anyone help me out here?

1 Answer 1


This error occurs due to the undeclared callback functions in SP.ClientContext.executeQueryAsync method:

SP.ClientContext.executeQueryAsync(succeededCallback, failedCallback)

The method accepts parameters:

  • succeededCallback - A function or a delegate of the method to call if the request executes successfully
  • failedCallback - A function or a delegate of the method to call if the request fails to execute


Add the missing callback functions, for example:

function onQuerySucceeded(sender, args) {
    //List Item has been created successfully...

function onQueryFailed(sender, args) {
    //Process error goes here...


How to: Complete basic operations using JavaScript library code in SharePoint 2013

  • Sorry, I did not mention that I do have those functions defined exactly as you mentioned. However, I realized I did not have them publicly exposed. I now have a new error. I get a Message from webpage stating "Request failed. Unexpected response data from server. null"
    – tnw
    Commented Mar 3, 2014 at 21:30
  • In that case, please make sure that the line where you set value for Last Name column is not causing that error.. Are you sure that field named "Last Name" (internal name) does exist in your list. For testing purposes you could just comment the line and run the code again Commented Mar 3, 2014 at 21:39
  • This happens regardless of that line and after all of this code executes. I've stepped through the lines in my debugger and the error is not thrown directly by any of them. I do see this in the console though: XMLHttpRequest for http://tnw2013/sites/Dev/_api/contextinfo required Cross Origin Resource Sharing (CORS). and XMLHttpRequest for http://tnw2013/sites/Dev/_api/contextinfo required CORS preflight. and XMLHttpRequest: Network Error 0x80070005, Access is denied.
    – tnw
    Commented Mar 3, 2014 at 22:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.