I do not know where I made a mistake. Unable to transfer data via Ajax to a PHP file.
<ul id="myTab" class="nav nav-tabs nav-justified"> <? while ($news = $news_sql->fetch(PDO::FETCH_BOTH)) { $NewsCategoryID = $news['NewsCategoryID']; echo '<li class=""><a id="NewsCategoryID onclick="myFunction()" href="#' . $news['NewsCategoryID'] . '" data-toggle="tab" aria-expanded="true">' . $news['NewsCategoryTitle'] . '</a></li>'; } ?> </ul> <table class="table table-striped" id="content"></table> <script> function myFunction() { var NewsCategoryID = '<?echo $NewsCategoryID?>' $.ajax({ type: "GET", url: "ajax_news.php", data: NewsCategoryID, dataType: "text", timeout: 30000, async: false, error: function(xhr) { console.log('Ошибка!' + xhr.status + ' ' + xhr.statusText); }, success: function(a) { document.getElementById("content").innerHTML = a; } }); } </script>
var NewsCategoryID = '<?echo $NewsCategoryID?>'
? PS Put a semicolon after the declaration. - mixasync: false
, by the way, is usually supposed to be shot on the spot. And once jQuery is used, then the constructions in the styledocument.getElementById("content").innerHTML
There is no sense to usedocument.getElementById("content").innerHTML
. - Regent