locked
REST APi RRS feed

  • Question

  • jquery ajax call does not call success of fail method. Same method is used at two places at one place it is working and at one place it is not. It is POST operation, item gets added in list but no message as it does not call success method.

    $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/lists/GetByTitle('" + listName + "')/items",
                type: "POST",
                contentType: "application/json;odata=verbose",
                data: JSON.stringify(item),
                headers: {
                    "Accept": "application/json;odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val()
                },           
                success: function (data) {
                    var idCurr = data.d.Id;
                    alert("message");
                  
                },
                error: function (error) {
                    alert(JSON.stringify(error));
                }

    • Moved by Patrick_Liang Wednesday, March 30, 2016 9:36 AM SharePoint 2013 issue
    Tuesday, March 29, 2016 10:17 AM

All replies

  • Hi,

    Is there any information in the console of the browser?

    Would you mind providing more details about how to reproduce this issue? I can try to make a test in my environment to see if it is reproducible.

    You can also monitor the requests using fiddler, it will help to provide more details.

    Best regards,

    Patrick

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Wednesday, March 30, 2016 9:56 AM
  • Hi

    In chrome it did not give any message but in firefox it gives unauthorized access while accessing list item message. To reproduce this issue you can make POST update operation in existing list sampele code as per below. What I observed is while making GET no error, but while updating list item using id

    _spPageContextInfo.webAbsoluteUrl +

    "/_api/lists/GetByTitle('"+ listName+ "')/items"+ "("+ id + ")",gives error of unauthorized access. This is random error. Please let me know if more info is required.

    $.when(promise1).done(

    function(p1) {

    varoldProjectStatus = p1.d.ProjectStatus;

                   

    varitem = {

                       

    "__metadata": { "type": getListItemType(listName) },

                       

    'OldProjectPhase': oldProjectStatus,

                       

    'ProjectStatus': "OnHold"


                    };

                    $.when(updateProjectStatus(item, queryProjectId)).done(

    function( data, textStatus, jqXHR ) {

                       

    try{

                            $(

    "#mainDiv").addClass("disabledbutton");

                           

    vard = newDate();

                           

    varcurrDate = d.getFullYear() + "/"+ (d.getMonth() + 1) + "/"+ d.getDate();

                            $(

    "#onHoldHeader").text("On Hold on "+ getDateFormat(currDate));

                            $(

    "#onHoldHeader").show();

                            $(

    '#loadinDiv').find('.modal-body').html("Project is On hold now.");

                            $(

    '#loadinDiv').modal('show');

                        }

                       

    catch(err) {

                            ajaxError( jqXHR,

    "AJAX successful but: "+ err.message );

                        }

                    }).fail( ajaxError ).always(

    function() {

                        alert(

    "fail");

                    });

    function

    updateProjectStatus(item, id) {

       

    try{

           

    return$.ajax({       

                url: _spPageContextInfo.webAbsoluteUrl +

    "/_api/lists/GetByTitle('"+ listName+ "')/items"+ "("+ id + ")",

                type:

    'POST',

                contentType:

    "application/json;odata=verbose",

                data: JSON.stringify(item),

                headers: {

                   

    "Accept": "application/json;odata=verbose",

                   

    "X-RequestDigest": $("#__REQUESTDIGEST").val(),

                   

    "X-HTTP-Method": "MERGE",

                   

    "If-Match": "*"


                },

                success:

    function(data) {

                    alert(

    "success");

                },

                error:

    function(error) {

                    alert(JSON.stringify(error));

                }

            });}

       

    catch(ex) {

            alert(

    "Exception"+ ex.message);

        }

    }

    Friday, April 1, 2016 5:13 AM
  • Hi Patrick

    This is the message given

    unreachable code after return statement sp.ribbon.debug.js:7330:16

    Security wrapper denied access to property (void 0) on privileged Javascript object. Support for exposing privileged objects to untrusted content via __exposedProps__ is being gradually removed - use WebIDL bindings or Components.utils.cloneInto instead. Note that only the first denied property access from a given global object will be reported.

    Friday, April 1, 2016 5:47 AM
  • Hi,

    “at one place it is working and at one place it is not”, in what page it doesn’t work?

    Would you mind providing more details about how to reproduce this issue? I can try to make a test in my environment to see if it is reproducible.

    Best regards,

    Patrick

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, April 5, 2016 10:02 AM