jQuery(function($) {
    layui.use(['layer'], function(){
        layer = layui.layer;
        $('button[lay-filter="baidu_translate_test"]').click(function () {
            $.ajax({
                url: ajaxurl,
                type: 'POST',
                dataType: 'json',
                timeout : 0,
                data: {
                    action : 'ctspider_ajax',
                    type : 'baidu_translate_test',
                    content : $('#baidu_translate_textdemo').val(),
                    from : $('select[name="baidu_translate_from"]').val(),
                    to : $('select[name="baidu_translate_to"]').val(),
                },
                beforeSend : function () {
                    layer.msg('<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i> 翻译中');
                },
                success : function (data) {
                    if (data.state){
                        layer.msg('翻译成功');
                        $('#baidu_translate_textdemo').val('');
                        $('#baidu_translate_textdemo').val(data['trans_result'][0]['dst']);
                    } else {
                        layer.msg('<i class="layui-icon layui-icon-close-fill" style="font-size: 20px; color: red; position: relative; top: 2px;">&#x1006;</i> ' +  data.error_msg, function(){
                        });
                    }
                },
                complete : function () {

                }
            });
        });
    });
});