How to return json value from FW1 controller to ajax?

29 views
Skip to first unread message

John Larry Limbo

unread,
Apr 3, 2022, 8:56:21 AM4/3/22
to framework-one
Hi Good day,

I need helpplease, how can I return a valid json value from my FW1 controller to my Ajax script.

city controller:
//provides delete functionality
  function delete( rc ) {
    var result = variables.cityComponent.DeleteCitybyId( rc.city_id );
     rc.message = ["<p class='success' id='success'>Record deleted sucessfully.</p>"];
    variables.fw.redirect( "city.list", "message" );
  }

Ajax:
 $.ajax({
        type: 'ajax',
        method: 'get',
        async: false,
        url: url + "?do=city.delete&p=lib&sp=city",
        data:{ city_id: city_id },
        dataType: 'json',
        success: function(response){
          response.forEach(function(response) {
            if(response.success)
            {
            }
            else
            {
            }        
        });      
        },
        error: function(jqXHR, textStatus, errorThrown){
          alert('Error: ' + textStatus + ' - ' + errorThrown);
        }
      });

I need to return a value that could tell my ajax that the action is success and completed.

Thank you.

John Whish

unread,
Apr 4, 2022, 2:33:52 PM4/4/22
to Unname
You can use something like:

function delete( rc ) {
    var result = variables.cityComponent.DeleteCitybyId( rc.city_id );
    variables.fw.renderData().type("JSON").data( {
       "success": result,
       "message": result ? "deleted" : "error"
    }
}

That'll return JSON which the javascript can consume.

--
FW/1 documentation: http://framework-one.github.io
FW/1 source code: http://github.com/framework-one/fw1
FW/1 chat / support: https://gitter.im/framework-one/fw1
FW/1 mailing list: http://groups.google.com/group/framework-one
---
You received this message because you are subscribed to the Google Groups "framework-one" group.
To unsubscribe from this group and stop receiving emails from it, send an email to framework-on...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/framework-one/5ac2db67-f109-4e99-af58-86b8e3fb15b0n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages