0
votes

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

3
Can you put console.log on your success function? Just log what the e variable has and you can likely see how to access the status property you provided in the screenshot. - Angelo
@Angelo just add in the post above. - dontbannedmeagain
Can you do console.log(e.responseText.status) or console.log(response.JSON.status)? This should provide you the value you need. - Angelo

3 Answers

0
votes

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).

0
votes

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

0
votes

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

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