Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在zend-framework3的视图中的div中加载HTML文件?_Jquery - Fatal编程技术网

Jquery 如何在zend-framework3的视图中的div中加载HTML文件?

Jquery 如何在zend-framework3的视图中的div中加载HTML文件?,jquery,Jquery,我正在开发一个电子邮件营销工具,需要在视图中的DIV中加载一个HTML模板。我正在使用zend-framework3。 我试图使用.load()函数,但它给出了一个错误。有人能帮我吗 我用的是这样的东西: $('#carregaTemplate').click(function(){ var qtdProdutos = $('#qtdProdutos').val(); $(function(){ if( qtdProdutos == 1 ) {

我正在开发一个电子邮件营销工具,需要在视图中的DIV中加载一个HTML模板。我正在使用zend-framework3。 我试图使用.load()函数,但它给出了一个错误。有人能帮我吗

我用的是这样的东西:

$('#carregaTemplate').click(function(){

    var qtdProdutos = $('#qtdProdutos').val();

    $(function(){
        if( qtdProdutos == 1 ) {
            $('#arquivoHtml').load('templates/sem_produtos.html');
        }
        if( qtdProdutos == 2 ) {
            $('#arquivoHtml').load('templates/dois_produtos.html');
        }
        if( qtdProdutos == 3 ) {
            $('#arquivoHtml').load('templates/tres_produtos.html');
        }
        if( qtdProdutos == 4 ) {
            $('#arquivoHtml').load('templates/quatro_produtos.html');
        }
    });
});

经过大量研究,我解决了以下问题:

我创建了一个正则表达式类型的路由。这种类型的路由允许您使用静态页面。请参见此处的示例:

在控制器中,我创建了以下负责呈现页面的函数:

公共职能行动{

在我的例子中,在DIV中加载页面的函数如下所示:

$('#carregaTemplate').click(function(){

    var qtdProdutos = $('#qtdProdutos').val();

    $(function(){
        if( qtdProdutos == 1 ) {
            $('#arquivoHtml').load('templates/sem_produtos.html');
        }
        if( qtdProdutos == 2 ) {
            $('#arquivoHtml').load('templates/dois_produtos.html');
        }
        if( qtdProdutos == 3 ) {
            $('#arquivoHtml').load('templates/tres_produtos.html');
        }
        if( qtdProdutos == 4 ) {
            $('#arquivoHtml').load('templates/quatro_produtos.html');
        }
    });
});
函数loadTemplate(){

var qtdProdutos=$('#qtdProdutos').val();
如果(qtdProdutos==1){
$('#arquivoHtml').load(“”,函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“除垢,防止错误:”;
$('arquivoHtml').html(msg+xhr.status+“”+xhr.statusText);
}
});
}
如果(qtdProdutos==2){
$('#arquivoHtml').load(“”,函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“除垢,防止错误:”;
$('arquivoHtml').html(msg+xhr.status+“”+xhr.statusText);
}
});
}
如果(qtdProdutos==3){
$('#arquivoHtml').load(“”,函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“除垢,防止错误:”;
$('arquivoHtml').html(msg+xhr.status+“”+xhr.statusText);
}
});
}
如果(qtdProdutos==4){
$('#arquivoHtml').load(“”,函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“除垢,防止错误:”;
$('arquivoHtml').html(msg+xhr.status+“”+xhr.statusText);
}
});
}
}

给出一个错误你会介意吗,告诉我们它给你带来了什么错误,老查普我在用这样的东西:这样的东西?如果你给我们看伪代码,你只会得到伪答案,来吧,为了改善你的体验,所以请阅读an,和以及如何创建a,而不需要使用
$(function()
在单击事件处理程序中。不会导致错误,但只是冗余对不起,伙计,我是堆栈中的新成员,我要重新措辞…我正是使用上述函数,我得到了错误500@riggsfully
    var qtdProdutos = $('#qtdProdutos').val();

    if( qtdProdutos == 1 ) {
        $('#arquivoHtml').load( "<?= $this->url('doc', ['page' => 'pagina']) ?>", function( response, status, xhr ){
            if( status == "error" ) {
                var msg = "Desculpe, ocorreu um erro: ";
                $('#arquivoHtml').html( msg + xhr.status + " " + xhr.statusText );
            }
        });
    }
    if( qtdProdutos == 2 ) {
        $('#arquivoHtml').load( "<?= $this->url('doc', ['page' => 'dois_produtos']) ?>", function( response, status, xhr ){
            if( status == "error" ) {
                var msg = "Desculpe, ocorreu um erro: ";
                $('#arquivoHtml').html( msg + xhr.status + " " + xhr.statusText );
            }
        });
    }
    if( qtdProdutos == 3 ) {
        $('#arquivoHtml').load( "<?= $this->url('doc', ['page' => 'tres_produtos']) ?>", function( response, status, xhr ){
            if( status == "error" ) {
                var msg = "Desculpe, ocorreu um erro: ";
                $('#arquivoHtml').html( msg + xhr.status + " " + xhr.statusText );
            }
        });
    }
    if( qtdProdutos == 4 ) {
        $('#arquivoHtml').load( "<?= $this->url('doc', ['page' => 'quatro_produtos']) ?>", function( response, status, xhr ){
            if( status == "error" ) {
                var msg = "Desculpe, ocorreu um erro: ";
                $('#arquivoHtml').html( msg + xhr.status + " " + xhr.statusText );
            }
        });
    }

}