我使用 javascript 从两个文件中捕获 html。在其中一个文件中,我包含了连接到我的数据库的信息。
但是当我这样做时,php 会在我的 html 中添加两个 "。所有文件都使用编码 UTF8 保存。
索引.php html
<div class="f-l" id="right-column"></div>
Javascript.js
$('#lead, #prospects').change(function() {
var kund_id = 'kund_id=' + $('#lead option:selected, #prospects option:selected').attr('value');
$.post(
'get_kund.php',
kund_id,
function(data){
$('#center-column').html(data)
});
$.post(
'get_kontaktperson.php',
kund_id,
function(data){
$('#right-column').html(data)
}); return false;
});
get_kontaktperson.php
include("db_connect.php");
$kund_id = $_POST['kund_id'];
$qry = "SELECT * FROM kontaktperson WHERE kund_id='$kund_id' ORDER BY id DESC";
$result=mysql_query($qry);
while($row=mysql_fetch_array($result)) {
echo 'some html'; }
db_connect.php
require_once('db_info_login.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: '
. mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die('Unable to select database');
}
mysql_query('SET NAMES utf8')
这会在 get_kontaktperson.php 的 html 代码之上添加“”:
为什么这对我来说似乎是个问题,<div class="kontaktperson">
被什么东西放错了地方。如果我拿走包含它会正确显示 html 内容。但是当我输入一些数据时,就会发生这种情况。右边栏的边距...
最佳答案
Chrome 的网络检查器使用这两个引号来表示元素内的内容。由于没有内容,所以显示两个引号,里面没有任何内容。
关于php - 使用 include 时,php 将 ""添加到 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18305454/