EasyUI Forum
October 10, 2024, 11:19:58 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Laravel show json response dialog box  (Read 8461 times)
dewan
Newbie
*
Posts: 24


View Profile
« on: January 25, 2019, 08:49:31 PM »

Hi

Is it possible to show the json response. Like when i delete the record i want to show the return json response

$(function(){
            $('#tt').edatagrid({
                url:"sales_invoice",
                saveUrl: '',
                updateUrl: '',
                destroyUrl: 'invoice_destroy',
                onDblClickRow: function (index,row) {                    
                    window.open("invoice_detail/"+row.invoice_id,"_blank")
                }
            });
        });

public function destroy(Request $request)
    {
        $data = InvoiceJournal::where('id', $request->id)->delete();
        if ($data) {

            return response()->json(['message'=>'Deleted Successfully'],200);
        }
        return response()->json(['message'=>'error while delete record'],200);
    }

how can i show this response.

Thank you.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: January 26, 2019, 06:55:47 PM »

You can custom the 'poster' function to retrieve any data from the server. Please look at this code.
Code:
<script>
$.extend($.fn.edatagrid.defaults, {
poster: function(url, data, success, error){
$.ajax({
type: 'post',
url: url,
data: data,
dataType: 'json',
success: function(data){
if (data.row){
success(data.row);
} else {
success(data);
}
if (data.message){
$.messager.alert('Message', data.message);
}
},
error: function(jqXHR, textStatus, errorThrown){
error({
jqXHR: jqXHR,
textStatus: textStatus,
errorThrown: errorThrown
});
}
});
}
})
</script>

You can return the json data to the browser.
Code:
{"row":{...},"message":"..."}

If the 'message' exists, the message alert will display.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!