简体   繁体   English

Laravel渲染没有HTML标签和标题的局部视图

[英]Laravel rendering a partial view without html tags and header

I'm trying to render a view with only html codes with NONE of them <html><head></head><body> ... tags because I want to return the code with AJAX and append it to another view, making it into a modal. 我正在尝试仅使用不带<html><head></head><body> ...标记的html代码呈现视图,因为我想使用AJAX返回代码并将其附加到另一个视图中,它变成一个模态。 I want to keep these modals in separate templates instead of having it all in one page. 我想将这些模态保存在单独的模板中,而不是全部放在一页中。 Is there a way in Laravel or can I only do it my own way? Laravel有办法吗,还是我只能自己做?

Controller: 控制器:

public function new() {
    return View('modals.new');
}

This is what I plan to do with the rendering in AJAX: 这是我计划在AJAX中进行渲染的方式:

function(url, selector) {
    $.get(url, function(data) {
         $(body).append(data);
    })
    $(selector).modal();
}

Right now it's rendering with the full html/head/body tags. 现在,它使用完整的html / head / body标签进行渲染。 Would I have to strip out the tags on my own? 我需要自己剥离标签吗?

Using jQuery you can manipulate the full page received and only insert parts of it 使用jQuery,您可以操纵接收到的整个页面,而只插入其中的一部分

function(url, selector) {
    $.get(url, function(data) {
         var $contentWanted = $(data).find(selector);
         $(body).append($contentWanted);
    })
    $(selector).modal();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM