[OpenLayers-Users] Getting server output when using save

Gabriel Nolasco nolasco_gabriel at yahoo.com.br
Wed Jul 7 05:22:10 EDT 2010


Adrian,

Try something like this:

var saveStrategy = new OpenLayers.Strategy.Save({
  onCommit: function(response){
    if(response.success()) {
      alert(response.priv.responseText);
    }
  }
});

Best regards,
Gabriel Nolasco


Message: 2
Date: Tue, 06 Jul 2010 15:19:31 +0300
From: Adrian Popa <adrian_gh.popa at romtelecom.ro>
Subject: [OpenLayers-Users] Getting server output when using save
    strategy
To: users <Users at openlayers.org>
Message-ID: <4C331F53.6050303 at romtelecom.ro>
Content-Type: text/plain; charset=UTF-8; format=flowed

Hello everyone,

I'm trying to create a callback function for the save strategy so that I 
can display a status message for the user in case there are problems 
with saving their changes (e.g. - session expired, etc).
I want the serverside script to send back a JSON formatted string that 
would describe what the problem was - for instance: 
({'failure':true,'error':'You do not have rights to make changes'}). I 
indend to eval this message and extract the error and show it to the user.

I have created a trigger that fires on "success", but I can't find 
anywhere the response from the server (so that I can parse it):

var saveStrategy = new OpenLayers.Strategy.Save();
saveStrategy.events.on({'success': function(event){
        alert("On save success");
}});

The event parameter that gets passed to the function has a 
"Strategy.Save" object and a "Protocol.Response" object. By browsing 
both of them I still couldn't find the original message returned by the 
server.

By the way, the server returns content-type text/html.

I noticed that the failure event is triggered when the server returns a 
500 error, but I wouldn't want to have to crash my server-side script on 
purpose in order to catch a problem on the client-side.

Am I missing something or doing something wrong?

Thanks,
Adrian



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100707/b407a5fa/attachment.html


More information about the Users mailing list