0

As above I am using a function to search a MySql database and display the results in a designated table but the return information is being displayed in HTML code instead (as below)

<style type="text/css">
.style39 {font-family: Geneva, Arial, Helvetica, sans-serif}
.style92 {font-size: 12px}
</style>
<table width="100%" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr class="PartListHeader"> 

My JavaScript:

$('input#PartNumber_Submit').on('click', function() {
    var PartNumber = $('input#PartNumber').val();
    if ($.trim(PartNumber) != ''){
        $.post('small-displays/PartSearchResults.php', {PartNumber: PartNumber}, function(data) {
            $('div#name-data').text(data);
        });
    }
});

I've been tinkering with the data . text but I'm well and truely lost and my mind has even lost with what to do. 1 hour and 50 minutes starring at the same small script! ARGH!

Something simple no doubt!

Any help would be much appreciated!

Thanks in advance,

2 Answers 2

6

You're using .text() which takes the passed in argument and places it into a text node within the specified element. If it's html, it won't render as html - you'll get the raw html source code. You want .html() instead:

        $('div#name-data').html(data);
                           ^^^^
Sign up to request clarification or add additional context in comments.

1 Comment

Ahhhhhh! You've just released a stress valve from my head!
0

Use this

 $('div#name-data').html(data); 

instead of this statement

$('div#name-data').text(data); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.