Support the ongoing development of Laravel.io →
Requests Views Blade
Last updated 2 years ago.
0

You are returning just javascript and i guess this will have a problem with the new lines. In my opinion it's better to only return html in either json response or just html. So your login function will then look like this: (With just html response)

public static function login()
{
      return View::make('ajax-login')->render();
}

When making your ajax call you can do something like this:

$.ajax({
[YourAjaxConfigSettings]
}).done(function(response){
       $('.modal_container').html('<div style="display:none"><a href="#myModal" id="popup-clicker" role="button" class="btn" data-toggle="modal"></a></div><div id="myModal" class="modal modal_hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content">'+ response +'</div></div></div>');
       document.getElementById('popup-clicker').click();
});
0

returning just plain html+js from controller will not magically update the elements on the browser. you must tell what to do with the result of the ajax response.

@arjan's example show how to do it.

0

Actually I will not be able to change my javascript code, because I have a modular system in my script and every module will use the same code for ajax requests.

Actually in this situation, I need a code snippet which will convert the html content into a single line. http://www.willpeavy.com/minifier/ is converting the code into a single line so if I can add a function, For instance, I can call the view file Class::minifyFunction(View::make('ajax-login')) so the html will be taken in a single line.

Is there an example code to achieve this or does laravel have function to do this?

0
Solution
preg_replace("/\s+|\n+|\r/", ' ', View::make('ajax-login'));

The code above has solved my problem. Thanks for your answers...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

toorta toorta Joined 27 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.