Status message "The changes have been saved" displays when updating user data using AJAX and Services module I am using navigator.geolocation.getCurrentPosition to get the user's current location, and then using the Services module to update the user's location (part of the user object) via AJAX.

Here is the AJAX call to the service:

jQuery.ajax({
  type: "PUT",
  url: "/api/internal/user/" + uid,
  data: JSON.stringify(geolocation),
  dataType: "json",
  contentType: "application/json",
  success: function(r) {
    console.log(r);
  }
});


The update works just fine, but when I navigate to another page afterwards, I get the status message: "The changes have been saved". After some digging, I found that this status message gets displayed any time user data is updated, which is fine usually, but will be confusing in this scenario since data is being updated behind the scenes. I'm assuming that since the user update is taking place via AJAX, the status message doesn't get displayed until next page load.

Is there any way to prevent Drupal from displaying this status message only when user data is updated using Services?
On your menu callback function ( at /api/internal/user/%user ) you can call drupal_get_messages('status');. This will clear the status messages displayed to the user. A better approach would be to check the message first:

$message = drupal_get_messages('status', false);
if( $message == t('The changes have been saved.') ) {
  drupal_get_messages('status');
}


If this is not a custom module, you should build one and use hook_page_alter() like this:

function yourmodule_page_alter(&amp;$page){
  if(arg(0) == 'api' &amp;&amp; arg(1) == 'internal' &amp;&amp; arg(2) == 'user') {
    $message = drupal_get_messages('status', false);
    if( $message == t('The changes have been saved.') ) {
      drupal_get_messages('status');
    }
  }
}