Jquery Generate barcode

Hi Guys,

I'm trying to  generate barcode through Jquery for MVC4 application.
I have downloaded these two jquery library:

<script src="~/Scripts/jquery-1.3.2.min.js"></script>
<script src="~/Scripts/jquery-barcode.js"></script>

and here is my HTML code :

<script src="~/Scripts/jquery-1.3.2.min.js"></script>
<script src="~/Scripts/jquery-barcode.js"></script>

<h2>Barcode training</h2>
<br />
<br />
<br />



<input type="button" value="Getbarcode" onclick="Gerbarcode();" />
<input type="text" id="txt" />
<div id="bcTarget2"></div>




@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">
        jQuery(function ($) {
            $("#bcTarget2").barcode(
                "1234567",
                "code128",
                {
                    barWidth: 2,
                    barHeight: 30
                });

        });

        function Gerbarcode() {
            var txtt = $("#txt").val();
            $.ajax({
                type: "GET",
                url: "/Printer/barcode",
                dataType: "html",
                data: { bar: txtt },
                success: function (data) {
                    if (data === "1") {
                        $("#bcTarget2").barcode("open");
                    }

                }
            });
        }

    </script>
}

Open in new window



Question:

When I type some number and trying to generate by clicking on the Getcarcode button I get nothing:



here is my server side code:

        public string barcode(string bar)
        {
            if(bar != null || bar != "")
            {
                return "1";
            }
            else
            {
                return "0";
            }
            
        }

Open in new window

LVL 1
Moti Mashiah.NET DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Which barcode library are you using?
0
Julian HansenCommented:
Just a question - why do this in jQuery? Why not AJAX the number back to the server and generate it there using a .Net library?
0
Steve BinkCommented:
The suggestion from Julian Hansen is a much better idea.  You're already doing an AJAX call to check the form data.  Processing and returning the bar code image will not be much additional overhead.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Pravin AsarPrincipal Systems EngineerCommented:
Have you tried debugging?
Do you get any javascript errors.

Look at project demo at google site.

https://code.google.com/p/jquery-barcode/
0
Prakash SamariyaIT ProfessionalCommented:
what do you mean by " $("#bcTarget2").barcode("open");"?

I think you have to give parameters like  
$("#bcTarget2").barcode(value, btype, settings);    
like  
$("#bcTarget2").barcode("1234567","code128"); //can omit settings part

Explanation and working example url is below
http://www.jqueryscript.net/other/Simple-jQuery-Based-Barcode-Generator-Barcode.html
http://www.jqueryscript.net/demo/Simple-jQuery-Based-Barcode-Generator-Barcode/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moti Mashiah.NET DeveloperAuthor Commented:
Here is my solution:

controller:
 public ActionResult GetBar(int id)
        {
            ALThompsonCRMEntities _db = new ALThompsonCRMEntities();
            var sr = _db.T_Recv_Serial.Where(p => p.recvEntryID == id).Select(p => new Insertserial { SerialNumber = p.SerialNumber }).ToList();
            return PartialView("_Genratebarcode", sr);
        }

view:
@model List<ALThompsonCRM.Models.ViewModel.Insertserial>




@foreach (var srn in Model)
{
    <div style="text-align:center">
        <div id="bcTarget"></div>
    </div>
       

}
<br />
<br />
<br />




<div style="text-align:center">
    <input type="button" class="btn btn-sm btn-primary" value="Print" onclick="printlabel();" />
</div>



<script src="~/Scripts/jquery-barcode.js"></script>
<script>

    function printlabel() {
        var divContents = $("#divid").html();
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>Labels</title>');
        printWindow.document.write('<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css" />');
        printWindow.document.write('</head><body>');
        printWindow.document.write('<h2>Labels</h2>');
        printWindow.document.write(divContents);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        printWindow.print();
    }
</script>

ajax:
function Genratlables(id) {
            var ser = $("#bcTarget").val();
            $.ajax({
                type: "GET",
                url: "/Receiving/GetBar",
                dataType: "html",
                data: { id: id },
                success: function (data) {
                    $("#genbar").html(data);
                    $("#genbar").dialog({ title: "Barcodes" }).dialog("open");
                    $("#bcTarget").barcode(ser, "code128");
                }

            });
        }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.