How to let anonymous users add items to a SharePoint list/library using client-side object model (JavaScript).

Follow the steps listed below:
  1. Enable Anonymous access at the Web Application level

    Go to SharePoint Central Administration, Application Management, and Manage Web Applications page. Select the Web Application, Authentication Providers, click on the zone, and select Enable anonymous access.


  2. Now, navigate to the corresponding web site, Site Actions, Site Permissions, and Anonymous Access. Configure what anonymous users can access at the site level


  3. Break the permission inheritance on the specific list in which you want to allow anonymous users to add items.

    Navigate to the list/library settings for the list in which you want to allow Anonymous users to add items. Navigate to List Settings, Permissions for this list, click on Stop Inheriting Permissions and click OK. Click on Anonymous Access and select Add 
    Items.


  4. Enable “AddItem” operation for the client object model for the Web Application. You can run the following code as a console application (equivalent PowerShell script also should work).

    //
    // Microsoft provides programming examples for illustration only,
    // without warranty either expressed or implied, including, but not
    // limited to, the implied warranties of merchantability and/or
    // fitness for a particular purpose.
    //
    // This sample assumes that you are familiar with the programming
    // language being demonstrated and the tools used to create and debug
    // procedures. Microsoft support professionals can help explain the
    // functionality of a particular procedure, but they will not modify
    // these examples to provide added functionality or construct
    // procedures to meet your specific needs. If you have limited
    // programming experience, you may want to contact a Microsoft
    // Certified Partner or the Microsoft fee-based consulting line at
    // (800) 936-5200.
    //
    // For more information about Microsoft Certified Partners, please
    // visit the following Microsoft Web site:
    //
     
    // Allows AddItem operation using anonymous access
     
    private static void AllowAnonAccess()
            {
                Console.WriteLine("Enabling Anonymous access....");
                SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webAppUrl));
                webApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove(typeof(Microsoft.SharePoint.SPList), "GetItems");
                webApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove(typeof(Microsoft.SharePoint.SPList), "AddItem");
                webApp.Update();
                Console.WriteLine("Enabled Anonymous access!");
            }
     
    // Revokes Add/Get Item operation using anonymous access
            private static void RemoveAnonAccess()
            {
                Console.WriteLine("Disabling Anonymous access....");
                SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webAppUrl));
                webApp.ClientCallableSettings.AnonymousRestrictedTypes.Add(typeof(Microsoft.SharePoint.SPList), "GetItems");
                webApp.ClientCallableSettings.AnonymousRestrictedTypes.Add(typeof(Microsoft.SharePoint.SPList), "AddItem");
                webApp.Update();
                Console.WriteLine("Disabled Anonymous access!");
            }


  5. Perform an IISReset after running this code.
You can make use of the createListItem() and retrieveListItems() method discussed in the following articles to Add/Get items using the anonymous account:

Note: If you are using a custom layouts page to execute the JS Script, make sure it’s accessible to the anonymous users. Inherit the custom page from UnsecuredLayoutsPageBase with AllowAnonymousAccess set to true.

Anonymous layouts page:





The item created by the anonymous user: