This is a migrated thread and some comments may be shown as answers.

OnDataBindingFailed

2 Answers 31 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 2
Jason asked on 23 Aug 2018, 09:16 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 04 Sep 2018, 12:16 PM
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.
0
Jason
Top achievements
Rank 2
answered on 10 Sep 2018, 01:39 PM

that's great

 

thanks.

Tags
ListBox
Asked by
Jason
Top achievements
Rank 2
Answers by
Peter Milchev
Telerik team
Jason
Top achievements
Rank 2
Share this question
or