Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
error in crome :
Uncaught SyntaxError: Invalid or unexpected token


output showing crome :
<a onclick="DeleteOrdersDtl('FH001" ');="">Delete</a>


error in firefox :
Uncaught SyntaxError: '' string literal contains an unescaped line break


output showing firefox:
<a onclick="DeleteOrdersDtl('FH001" ');="">Delete</a>



any one can help me

What I have tried:

i have try 
<pre>
    function getorderdtl(PlanNo) {
        $.ajax({
            url: "/Home/GetOrdersDtl?PlanNo=" + PlanNo,
            type: "GET",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {
                var html = '';
                $.each(result, function (key, item) {
                    html += '<tr>';
                    html += '<td>' + item.VsNo + '</td>';

                    html += '<td>' + item.Weight + '</td>';
                    html += '<td>' + item.Quality + '</td>';
                    html += '<td>' + item.GSM + '</td>';
                    html += '<td>' + item.Width + '</td>';
                    html += '<td>' + item.Length + '</td>';

                    html += "<td><a  onclick='return getbyID(" + item.TxnNo + ")'>Edit</a> | <a  onclick=DeleteOrdersDtl('"+ item.TxnNo +"');>Delete</a></td>";
                    html += '</tr>';
                });
                $('.tbody').html(html);
            },
            error: function (errormessage) {
                alert(errormessage.responseText);
            }
        });
    }

but it not woorking for me

i also try another one
function getorderdtl(PlanNo) {

    $('#orderdtl').DataTable({
        destroy: true,
        "ajax": {
            "url": '/Home/GetOrdersDtl?PlanNo=' + PlanNo,
            "type": 'POST',
            "datatype": 'json'
        },
        "columns": [
             { "data": "VsNo", "name": "VsNo", "autoWidth": true },
           { "data": "Weight", "name": "Weight", "autoWidth": true },
              { "data": "Quality", "name": " Quality ", "autoWidth": true },

              { "data": "GSM", "title": "GSM", "name": "GSM", "autoWidth": true },
               { "data": "Width", "title": "Width", "name": "Width", "autoWidth": true },
              { "data": "Length", "name": "Length", "autoWidth": true },
               {
                   "render": function (data, type, full) {
                       return "<a class='btn-danger' onclick=DeleteOrdersDtl('" + full.TxnNo + "')>"></a> | <a style='font-size:12; color:white;  background-color:green; padding:4px;border-radius:4px;margin-left:2px' class='btn-primary' onclick=EditOrderDtl('" + full.TxnNo + "')>^__i class="fa fa-edit"></a>";
                   }
               }
                
        ]

    });

}


other way i tried

return '<a class="btn-danger" onclick=DeleteOrdersDtl("'+ full.TxnNo +'")></a>';



return '<a class="btn-danger" onclick=DeleteOrdersDtl('+ full.TxnNo +')></a>';

but its not working for me
Posted
Updated 1-Jun-21 22:23pm
v2

If you need to support Internet Explorer, then try:
JavaScript
html += "<td><a  onclick='return getbyID(\"" + item.TxnNo + "\")'>Edit</a> | <a  onclick='DeleteOrdersDtl(\""+ item.TxnNo +"\");'>Delete</a></td>";
If you can drop Internet Explorer support, then use a template literal[^]:
Javscript
html += `<td><a  onclick='return getbyID("${item.TxnNo}")'>Edit</a> | <a  onclick='DeleteOrdersDtl("${item.TxnNo}");'>Delete</a></td>`;
Alternatively, use a template library to generate the HTML - for example, Handlebars[^]:
HTML
<script id="order-detail-template" type="text/x-handlebars-template">
{{#each this}}
<tr>
    <td>{{VsNo}}</td>
    <td>{{Weight}}</td>
    <td>{{Quality}}</td>
    <td>{{GSM}}</td>
    <td>{{Width}}</td>
    <td>{{Length}}</td>
    <td><a onclick="return getbyID('{{TxnNo}}')">Edit</a> | <a onclick='DeleteOrdersDtl("{{TxnNo}}');">Delete</a></td>
</tr>
{{/each}}
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js" integrity="sha512-RNLkV3d+aLtfcpEyFG8jRbnWHxUqVZozacROI4J2F1sTaDqo1dPQYs01OMi1t1w9Y2FdbSCDSQ2ZVdAC8bzgAg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script>
$(function(){
    const orderDetailTemplate = Handlebars.compile($("#order-detail-template").html());
    ...
    const getorderdtl = function(PlanNo) {
        $.ajax({
            url: "/Home/GetOrdersDtl?PlanNo=" + encodeURIComponent(PlanNo),
            type: "GET",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {
                const html = orderDetailTemplate(result);
                $(".tbody").html(html);
            },
            error: function (errormessage) {
                alert(errormessage.responseText);
            }
        });
    };
    ...
});
</script>
 
Share this answer
 
Hi Richard Deeming thanks for support,

hi have find the solution,
i am tring to pass string data which may content space,

i change the para meter "string" to "int" and it works for me thanks..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900