laravel blade variable inside javascript

Viewed 28

I tried to access variable inside blade syntax:

            success: function(resp) {
                console.log(resp)
                var MsgClass = 'alert-danger';
                $("#overlay").hide();
                if(resp.success) {
                    MsgClass = 'alert-success';
                    window.location.href = "{{ asset('public/exports/'+resp.filename) }}"
                }                    
            },

But I get

Use of undefined constant resp - assumed 'resp'

How can I get this variable inside the syntax?

1 Answers

Just use like this

window.location.href = '"{{url('')}}/public/exports/"'+resp.filename
Related