error in function JS with two parameters

4

I have a button that invokes a JS function, but I have not been able to send more than one parameter

                           $("#msgPrueba").html('<script>$("#exampleModalx").modal({backdrop: "", keyboard: false});</script><div class="modal fade" id="exampleModalx" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">' +
'<div class="modal-dialog" role="document">'+
'<div class="modal-content">'+
'<div class="modal-header">'+
'<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>'+
'<h4 class="modal-title" id="exampleModalLabel">
<span style="font-size:14px">:: Factura '+ factura +' ;;</style>' +
'</div>'+
'<div class="modal-body">'+
'<center><img src="../Images/ok.jpg" width="70px" height="60px"/><br/>"' + data + '"</center>' +
'<center><img src="../Images/ok.png" width="30px" height="30px"/><br/><br/>' + data + '<br/><span style="font-size:12px;color:green">Serie(s) guardada(s) exitosamente</span></center>'+
'</div>'+
'<div class="modal-footer">'+                
'<button type="button" class="btn btn-default" id="btnCerrarModal" onClick="facturaSer( "' + factura + '","SI")"  data-dismiss="modal">Cerrar</button>' +
'</div>'+
'</div>'+
'</div>'+
'</div>');

and my function is

function facturaSer(varfactura, varplazos) {
    alert(varplazos);

    var fact = varfactura
        //alert(fact);
        var cargando = $("#muestraSeccion").html("<center><img  src='../Images/cargando1.gif' height='50px' width='50px'/><br/>Un momento por favor...<center>");

    $.ajax({
        type: 'POST',
        url: 'buscaFactura',
        data: {
            "factura": fact
        },
        success: function (resultado) {
            //cargando.hide();
            $("#muestraSeccion").hide().html(resultado).fadeIn("fast");

        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log(jqXHR, textStatus, errorThrown);
            if (jqXHR.status === 0) {

                alert('Not connect: Verify Network.=(');

            } else if (jqXHR.status == 404) {

                alert('Requested page not found [404].');

            } else if (jqXHR.status == 500) {

                alert('Error Interno del Servidor [500].');

            } else if (textStatus === 'parsererror') {

                alert('Requested JSON parse failed.');

            } else if (textStatus === 'timeout') {

                alert('Time out error.');

            } else if (textStatus === 'abort') {

                alert('Ajax request aborted.');

            } else {

                alert('Uncaught Error: ' + jqXHR.responseText);

            }

        }
    });
}

and I get an error VM540 inicioEmpresariales:2 Uncaught SyntaxError: Unexpected token } , am I calling the function correctly?

    
asked by Ivxn 06.10.2016 в 18:48
source

1 answer

1

You have several errors in the JS, such as tags that do not close, problems with the Comillas in the close button, lack of; in "var fac = ..." for the to concatenate double quotes you must use \ ", besides how are you creating a script tag you must close it with but the browser does not correctly interpret the script

<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div id="msgPrueba"></div>
<script>
var factura = "factura";
var data = "data";
var comilla = "'";
var htmlStr = "<script>$('#exampleModalx').modal({backdrop: '', keyboard: false});<\/script><div class='modal fade' id='exampleModalx' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel'>" +
"<div class='modal-dialog' role='document'>" +
"<div class='modal-content'>" +
"<div class='modal-header'>" +
"<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>" +
"<h4 class='modal-title' id='exampleModalLabel'><span style='font-size:14px'>:: Factura " + factura + " ;;</span>" +
"</h4>" +
"<div class='modal-body'>" +
"<center><img src='../Images/ok.jpg' width='70px' height='60px'/><br/>'" + data + "'</center>" +
"<center><img src='../Images/ok.png' width='30px' height='30px'/><br/><br/>" + data + "<br/><span style='font-size:12px;color:green'>Serie(s) guardada(s) exitosamente</span></center>" +
"</div>" +
"<div class='modal-footer'>" +
"<button type='button' class='btn btn-default' id='btnCerrarModal' onClick=\"facturaSer('"+factura+ "','" +"SI"+"');\"  data-dismiss='modal'>Cerrar</button>" +
"</div>" +
"</div>" +
"</div>" +
"</div>";

$("#msgPrueba").html(htmlStr);


function facturaSer(varfactura, varplazos) {

alert(varplazos);

var fact = varfactura;
//alert(fact);
var cargando = $("#muestraSeccion").html("<center><img  src='../Images/cargando1.gif' height='50px' width='50px'/><br/>Un momento por favor...<center>");

$.ajax({
    type: 'POST',
    url: 'buscaFactura',
    data: {
        "factura": fact
    },
    success: function (resultado) {
        //cargando.hide();
        $("#muestraSeccion").hide().html(resultado).fadeIn("fast");

    },
    error: function (jqXHR, textStatus, errorThrown) {
        console.log(jqXHR, textStatus, errorThrown);
        if (jqXHR.status === 0) {

            alert('Not connect: Verify Network.=(');

        } else if (jqXHR.status == 404) {

            alert('Requested page not found [404].');

        } else if (jqXHR.status == 500) {

            alert('Error Interno del Servidor [500].');

        } else if (textStatus === 'parsererror') {

            alert('Requested JSON parse failed.');

        } else if (textStatus === 'timeout') {

            alert('Time out error.');

        } else if (textStatus === 'abort') {

            alert('Ajax request aborted.');

        } else {

            alert('Uncaught Error: ' + jqXHR.responseText);

        }
    }
});
}
</script>
    
answered by 06.10.2016 / 21:53
source