dontbannedmeagain
dontbannedmeagain

Reputation: 480

Kendo DataSource catch server response

In my kendo dataSource > transport > update. I want to catch a server response status (refer image), but none of this methods trigger an alert. Any idea why?

update: {
  url:  "./getRevenueAccounts.php",
  type: "POST",
  data: function() {
          return { 
            method: "editRevenueAccounts"
          }
  },	
  success: function(e) {
   if(e.status == 'duplicate'){
    alert('Trigger 1');
   }
  },
  error: function(e) {
    if (e.errorThrown == 'duplicate') {
      alert("Trigger 2");
    }else if(e.status == 'duplicate' ){
      alert("Trigger 3")
    }
  },	
  complete: function (e) {
    if(e.status == 'duplicate'){
      alert('Trigger 4');
    }
  }
},

enter image description here

console.log(e) screen shot

enter image description here

Upvotes: 0

Views: 1333

Answers (3)

dontbannedmeagain
dontbannedmeagain

Reputation: 480

Is not a good method to apply, but it works to fetch the response.

if(e.responseText=='{"status":"duplicate"}'){
   kendo.alert('duplicate data');
}

Upvotes: 0

calinaadi
calinaadi

Reputation: 1466

You need to make an ajax call inside the update function. Like:

var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
      /* implementation omitted for brevity */
    },
    update: function(options) {
      // make JSONP request to https://demos.telerik.com/kendo-ui/service/products/update
      $.ajax({
        url: "https://demos.telerik.com/kendo-ui/service/products/update",
        dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
        // send the updated data items as the "models" service parameter encoded in JSON
        data: {
          models: kendo.stringify(options.data.models)
        },
        success: function(result) {
          // notify the data source that the request succeeded
          options.success(result);
        },
        error: function(result) {
          // notify the data source that the request failed
          options.error(result);
        }
      });
    }
  },
  batch: true,
  schema: {
    model: { id: "ProductID" }
  }
});

For more details please check this from telerik documentation: https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/transport.update

Upvotes: 0

Angelo
Angelo

Reputation: 1666

Try the following code for your success function:

success: function(e) {
   if(e.responseText.status == 'duplicate'){
    alert('Trigger 1');
   }
  },

Essentially, you are looking at the status property when you should have been looking at the responseText property to get the status (which is another property on that object).

Upvotes: 0

Related Questions