Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

JavaScript runtime error: Object doesn't support property or method 'add_requestSucceeded' in Sharepoint 2013/ SharePoint Apps

$
0
0
Hi,

I am new to Javascript and Sharepoint 2013.
I am following a tutorial and I created a lab exercise, in it I am adding a new item/record/row in a list via Javascript.

In this example the list is created in Hostweb and I am accessing it in SharePoint App i.e. in AppWeb. 
In the lab exercise code was written in the App.JS file, I used the same code but placed the whole code in new JS file as App1.JS and called the function of App1.JS at the document.ready function of App.JS.

The code works fine if the code is placed in App.JS but fails when it is called from App1.JS and it gives the following error:
**

 - "JavaScript runtime error: Object doesn't support property or method
   'add_requestSucceeded'"

the code is :

function createCategory() {
    var ctx = new SP.ClientContext(appWebUrl);//Get the SharePoint Context object based upon the URL
    var appCtxSite = new SP.AppContextSite(ctx, hostWebUrl);

    var web = appCtxSite.get_web(); //Get the Site 

    var list = web.get_lists().getByTitle("CategoryList"); //Get the List based upon the Title
    var listCreationInformation = new SP.ListItemCreationInformation(); //Object for creating Item in the List
    var listItem = list.addItem(listCreationInformation);

    listItem.set_item("Title", $("#CategoryId").val());
    listItem.set_item("CategoryName", $("#CategoryName").val());
    listItem.update(); //Update the List Item

    ctx.load(listItem);
    //Execute the batch Asynchronously
    ctx.executeQueryAsync(
        Function.createDelegate(this, success),
        Function.createDelegate(this, fail)
       );
}

Can someone please tell me the cause of the error and suggest its solution.

Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>