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();
});
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.
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?
preg_replace("/\s+|\n+|\r/", ' ', View::make('ajax-login'));
The code above has solved my problem. Thanks for your answers...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community