Skip to main content

#OData- Calling SAP service that has Single sign on access.

we can do multiple call in same time. as AJAX is Async if you need to do a action after 1 or more call's success, use the below way.

Syntax
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ).done(function( a1, a2 ) {

  // a1 and a2 are arguments resolved for the page1 and page2 ajax requests, respectively.
  // Each argument is an array with the following structure: [ data, statusText, jqXHR ]
  var data = a1[ 0 ] + a2[ 0 ];

  if ( /Whip It/.test( data ) ) {
    alert( "We got what we came for!" );
  }

});

https://api.jquery.com/jquery.when/

Implementation

    var async1 = DoGetCall('url 1 here');
    var async2 = DoGetCall('url 2 here');
    var async3 = DoGetCall('url 3 here');
    var async4 = DoGetCall('url 4 here');
    var async5 = DoGetCall('url 5 here');

    // create call to get all exixting COR detail
    $.when(async1, async2, async3, async4, async5).done(function (result1, result2, result3, result4, result5) {
        if (result1[2].status === 200 && result2[2].status === 200 && result3[2].status === 200 && result4[2].status === 200 && result5[2].status === 200) {
            response1 = JSON.parse(result1[2].responseText).data.employee;
            response2 = JSON.parse(result2[2].responseText).data.Man;
            response3 = JSON.parse(result3[2].responseText).data.d;
            response4 = JSON.parse(result4[2].responseText).data.XXX;
            response5 = JSON.parse(result5[2].responseText).data.YYY;
            try {
                globalToken = result1[2].getResponseHeader('X-CSRF-Token'); console.log(globalToken);
            } catch (e) { console.log(e); }

// write the logic here...

  }
        else {
        alert('Get failed to return'); 
        }


    }).fail(function (xhr, status, error) {
        if (xhr.status === 404) {
            errorMessage = error;
        } else {
            errorMessage = xhr.responseJSON.error.message.value;
        }

    });

function DoGetCall(url) {
       return $.ajax({
        type: 'Get',
        beforeSend: function (xhr, settings) {
            xhr.setRequestHeader('X-CSRF-Token', "Fetch");
        },
        cache: false,
        url: url,
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true
    });
 }


  // Calling
allGetCalls.push(DoGetCall('url1');
allGetCalls.push(DoGetCall('url2');
                $.when.apply($, allGetCalls)
                    .done(function () {
                        $.each(arguments, function (i, data) {
                                     console.log(data[2]); //hr is the value returned by each of the ajax requests
                            getOutputList.push(data[2]);
                        });



Comments

Popular posts from this blog

#EF : DbEntityValidationException - How can I easily tell what caused the error?

While calling  SaveChanges  on my  DbContext , I get the following exception: System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. This is all fine and dandy, but I don't want to attach a debugger every time this exception occurs. More over, in production environments I cannot easily attach a debugger so I have to go to great lengths to reproduce these errors. How can I see the details hidden within the  DbEntityValidationException ? Answer :  The easiest solution is to override SaveChanges on your entities class. You can catch the DbEntityValidationException, unwrap the actual errors and create a new DbEntityValidationException with the improved message. Create a partial class next to your SomethingSomething.Context.cs file. Use the code at the bottom of this post. That's it. Your implementation will automatically use the overriden Save...

Use Log4Net in C# windows form Application

we are going to learn on how to use the Log4Net library for creating logs. Create a new windows form application in VS. Install Log4Net library Add to AssemblyInfo.cs  Configure in  App.config Use in code  Install Log4Net library Then install the Log4Net library from the Nuget Package library.           log4net by The Apache software foundation 2.0.8 (i installed the latest). Add to AssemblyInfo.cs  After installing this package, open up AssemblyInfo .cs file under the Properties folder and add the log4net assembly information into it (under the other assembly information.).    [assembly: log4net.Config.XmlConfigurator(Watch= true )]  Configure in  App.config Now, open the App.config file and enter required details for LogNet to work. <configSections>       <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2....

#MVC Authorize Attribute

Authorization is the process of determining the rights of an authenticated user for accessing the application's resources. The Asp.Net MVC Framework has a AuthorizeAttribute filter for filtering the authorized user to access a resource. Authorize Attribute Properties Properties Description Roles Gets or sets the roles required to access the controller or action method. Users Gets or sets the user names required to access the controller or action method. Filtering Users by Users Property Suppose you want to allow the access of AdminProfile to only shailendra and mohan users then you can specify the authorize users list to Users property as shown below. [ Authorize ( Users = "Raj,Deena,Siva,Gow" )] public ActionResult AdminProfile () { return View (); } Filtering Users by Roles Property Suppose you want to allow the access of AdminProfile action to only Admin and SubAdmin roles then you can specify the authorize roles...