OnDataBindingFailed

3 posts, 1 answers
  1. Jason
    Jason avatar
    29 posts
    Member since:
    Aug 2009

    Posted 23 Aug 2018 Link to this post

    I'm having difficulty getting the exception from the OnDataBindingFailed event

    the event fires as expected, but the eventArgs object doesn't have the methods

         get_exception() - returns the deserialized response text.
         get_responseText() - returns the response text from the service.

    as described in this doc link

         https://docs.telerik.com/devtools/aspnet-ajax/controls/listview/data-binding/client-side/api

    The error that is showing on the console is

         Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource ... blah blah blah

    what am in missing?

  2. Answer
    Peter Milchev
    Admin
    Peter Milchev avatar
    588 posts

    Posted 04 Sep 2018 Link to this post

    Hello Jason,

    The responses with Cross-Origin errors intentionally filter-out the headers and any other possibly sensitive information as you can see in this StackOverflow thread: Is it possible to trap CORS errors?

    Nevertheless, you can use the following conditions to differentiate the CORS from a normal error: 

    function OnDataBindingFailed(sender, args) {
        if (args.get_responseText) {
            var exception = args.get_exception();
            var responseText = args.get_responseText();
        } else {
            // most probably CORS error.
        }
    }

    Basically, the internal fail handler builds the arguments similar to: 

    // other code here
    if (response && response.responseText)
    {
        var exception;
        try
        {
            exception = Sys.Serialization.JavaScriptSerializer.deserialize(response.responseText);
        }
        catch (e) { }
     
        this._buildEventArgs(args,
        {
            exception: exception,
            responseText: response.responseText
        });
    }
    // other code here

    That is why when the cross-origin request fails, the arguments are not built this way and the methods are not available.

    To fix the error itself, basically, you should allow the cross-origin request to all or just some specific domains and addresses. How to allow it depends on the type of your service.

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Jason
    Jason avatar
    29 posts
    Member since:
    Aug 2009

    Posted 10 Sep 2018 in reply to Peter Milchev Link to this post

    that's great

     

    thanks.

Back to Top