У меня есть 2 страницы HTML и PHP. где таблица выбирается на основе того, какая опция тогда загружается таблица и сценарий для этой таблицы. При добавлении сценария в ответе PHP Echo. Я получаю( Undefined variable $btn in) только после добавления 3 -го секции я предполагаю, что он имеет какое -то отношение к ответу или способам его вставки. Кто -нибудь может сказать мне, что не так? Или направлять меня? Chatgpt не знаю, ура, моя последняя надежда ... < /p>
Почему код перестает работать и ошибочно выходить после добавления 3 -го секции кода?
Как только код будет работать, я защичу его с помощью PDO и подготовленных операторов, давайте сосредоточимся на вопросе < /p>
// This function is user to insert data in database
$('#btnSaveAction').on('click', function () {
params = ''
$('td[contentEditable=\"true\"]').each(function () {
if ($(this).text() != '') {
if (params != '') {
params += '&';
}
params += $(this).data('id') + '=' + $(this).text();
}
});
if (params != '') {
alert(params);// santize data
$.ajax({
url: 'function.php',
type: 'POST',
data: params,
success: function (response) {
$('#ajax-response').append(response);
$('td[contentEditable=\"true\"]').text('');
}
});
return false;
}
});
// This function is used for edit the row to make it editable
$('#tbl').on('click', '.edit', function () {
$('#tbl').find('.save, .cancel').hide();
$('#tbl').find('.edit').show();
$(this).hide().siblings('.save, .cancel').show();
$(this).closest('td').siblings().each(
function () {
var inp = $(this).find('input');
if (inp.length) {
$(this).text(inp.val());
} else {
var t = $(this).text();
$(this).attr('contentEditable', 'true');
}
});
});
// This function is used for edit the row to make it editable
$('#tbl').on('click', '.cancel', function () {
$('#tbl').find('.save, .cancel').hide();
$(this).hide().siblings('.edit').show();
$(this).closest('td').siblings().each(
function () {
$(this).attr('contentEditable', 'false');
location.reload();
});
});
< /code>
И после того, как вы добавите это, его запуска в ошибку, но все это выглядит правильно < /p>
// This function is used for saving the edit data in database
$('#tbl').on('click', '.save', function () {
var $btn = $(this);
$('#tbl').find('.save, .cancel').hide();
$btn.hide().siblings('.edit').show();
params = '';
var id = $btn.data('id');
$(this).closest('td').siblings().each(function () {
$(this).attr('contentEditable', 'false');
if (params != '') {
params += '&';
}
params += $(this).data('id') + '=' + $(this).text();
});
params += '&id' + '=' + id;
alert(params);// santize data
if (params != '') {
$.ajax({
url: 'function.php',
type: 'POST',
data: params,
success: function (response) {
$('#ajax-response').append(response);
// $('td[contentEditable='true']').text('');
}
});
return false;
}
});
// this ajax is using for deleting the row
$('#tbl').on('click', '.del', function () {
var el = this;
var deleteid = $(this).data('id');
console.log(deleteid);
var confirmalert = confirm('Are you sure?');
if (confirmalert == true) {
$.ajax({
url: 'function.php',
type: 'POST',
data: {
id: deleteid,
action: 'del'
},
success: function (response) {
if (response == 1) {
// Remove row from HTML Table
$(el).closest('tr').css('background', 'tomato');
$(el).closest('tr').fadeOut(800, function () {
$(this).remove();
});
} else {
alert('Invalid ID.');
}
}
});
}
});
< /code>
Я попробовал это < /p>
// using this
$("#ajax-response").append(response);
//but can also use this
var maincontent = document.getElementById("ajax-response");
maincontent.innerHTML = response;
//or this
$.getScript('asset/custom.js'); // Execute the JavaScript file
< /code>
Это также не работает, ни размещение до или после HTML < /p>
$('script', response).each(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.text = this.innerHTML;
document.body.appendChild(script);
< /code>
html
< /p>
Manager combined Console
#btnSaveAction {
display: inline-block;
color: #444;
border: 1px solid #CCC;
background: #DDD;
box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.2);
cursor: pointer;
vertical-align: middle;
max-width: 100px;
padding: 5px;
text-align: center;
}
// Load table data when a table is selected
$(document).on('change', '#tableSelect', function() {
var table = $(this).val();
if (table) {
$.ajax({
url: 'function77.php',
type: 'GET',
data: { table: table },
success: function(response) {
// Replace the current content with the new response
$("#tableData").html(response);
$('script', response).each(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.text = this.innerHTML;
document.body.appendChild(script);
});
}
});
} else {
$('#tableData').html('');
}
});
Business Console
Select Business
Business Manager
1-Location1
2-Location2
3-Location3
4-Location4
5-Location5
6-Location6
7-Location7
8-Location8
9-Location9
10-Location10
< /code>
и функция77.php < /p>
Подробнее здесь: https://stackoverflow.com/questions/794 ... -of-erorrs
При добавлении скрипта в качестве ответа Ajax все виды ошибок [закрыто] ⇐ Javascript
Форум по Javascript
1739987858
Anonymous
У меня есть 2 страницы HTML и PHP. где таблица выбирается на основе того, какая опция тогда загружается таблица и сценарий для этой таблицы. При добавлении сценария в ответе PHP Echo. Я получаю( Undefined variable $btn in) только после добавления 3 -го секции я предполагаю, что он имеет какое -то отношение к ответу или способам его вставки. Кто -нибудь может сказать мне, что не так? Или направлять меня? Chatgpt не знаю, ура, моя последняя надежда ... < /p>
Почему код перестает работать и ошибочно выходить после добавления 3 -го секции кода?
Как только код будет работать, я защичу его с помощью PDO и подготовленных операторов, давайте сосредоточимся на вопросе < /p>
// This function is user to insert data in database
$('#btnSaveAction').on('click', function () {
params = ''
$('td[contentEditable=\"true\"]').each(function () {
if ($(this).text() != '') {
if (params != '') {
params += '&';
}
params += $(this).data('id') + '=' + $(this).text();
}
});
if (params != '') {
alert(params);// santize data
$.ajax({
url: 'function.php',
type: 'POST',
data: params,
success: function (response) {
$('#ajax-response').append(response);
$('td[contentEditable=\"true\"]').text('');
}
});
return false;
}
});
// This function is used for edit the row to make it editable
$('#tbl').on('click', '.edit', function () {
$('#tbl').find('.save, .cancel').hide();
$('#tbl').find('.edit').show();
$(this).hide().siblings('.save, .cancel').show();
$(this).closest('td').siblings().each(
function () {
var inp = $(this).find('input');
if (inp.length) {
$(this).text(inp.val());
} else {
var t = $(this).text();
$(this).attr('contentEditable', 'true');
}
});
});
// This function is used for edit the row to make it editable
$('#tbl').on('click', '.cancel', function () {
$('#tbl').find('.save, .cancel').hide();
$(this).hide().siblings('.edit').show();
$(this).closest('td').siblings().each(
function () {
$(this).attr('contentEditable', 'false');
location.reload();
});
});
< /code>
И после того, как вы добавите это, его запуска в ошибку, но все это выглядит правильно < /p>
// This function is used for saving the edit data in database
$('#tbl').on('click', '.save', function () {
var $btn = $(this);
$('#tbl').find('.save, .cancel').hide();
$btn.hide().siblings('.edit').show();
params = '';
var id = $btn.data('id');
$(this).closest('td').siblings().each(function () {
$(this).attr('contentEditable', 'false');
if (params != '') {
params += '&';
}
params += $(this).data('id') + '=' + $(this).text();
});
params += '&id' + '=' + id;
alert(params);// santize data
if (params != '') {
$.ajax({
url: 'function.php',
type: 'POST',
data: params,
success: function (response) {
$('#ajax-response').append(response);
// $('td[contentEditable='true']').text('');
}
});
return false;
}
});
// this ajax is using for deleting the row
$('#tbl').on('click', '.del', function () {
var el = this;
var deleteid = $(this).data('id');
console.log(deleteid);
var confirmalert = confirm('Are you sure?');
if (confirmalert == true) {
$.ajax({
url: 'function.php',
type: 'POST',
data: {
id: deleteid,
action: 'del'
},
success: function (response) {
if (response == 1) {
// Remove row from HTML Table
$(el).closest('tr').css('background', 'tomato');
$(el).closest('tr').fadeOut(800, function () {
$(this).remove();
});
} else {
alert('Invalid ID.');
}
}
});
}
});
< /code>
Я попробовал это < /p>
// using this
$("#ajax-response").append(response);
//but can also use this
var maincontent = document.getElementById("ajax-response");
maincontent.innerHTML = response;
//or this
$.getScript('asset/custom.js'); // Execute the JavaScript file
< /code>
Это также не работает, ни размещение до или после HTML < /p>
$('script', response).each(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.text = this.innerHTML;
document.body.appendChild(script);
< /code>
html
< /p>
Manager combined Console
#btnSaveAction {
display: inline-block;
color: #444;
border: 1px solid #CCC;
background: #DDD;
box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.2);
cursor: pointer;
vertical-align: middle;
max-width: 100px;
padding: 5px;
text-align: center;
}
// Load table data when a table is selected
$(document).on('change', '#tableSelect', function() {
var table = $(this).val();
if (table) {
$.ajax({
url: 'function77.php',
type: 'GET',
data: { table: table },
success: function(response) {
// Replace the current content with the new response
$("#tableData").html(response);
$('script', response).each(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.text = this.innerHTML;
document.body.appendChild(script);
});
}
});
} else {
$('#tableData').html('');
}
});
Business Console
Select Business
Business Manager
1-Location1
2-Location2
3-Location3
4-Location4
5-Location5
6-Location6
7-Location7
8-Location8
9-Location9
10-Location10
< /code>
и функция77.php < /p>
Подробнее здесь: [url]https://stackoverflow.com/questions/79452297/when-adding-script-as-a-ajax-resonse-all-kinds-of-erorrs[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия