我从数据库中带回的某些记录包含撇号。
各种记录的名称如下:
CC CHÂTEAU D'IF
检查元素,数据属性如下:
data-vesselname="CC CHÂTEAU D" IF'
我需要数据属性如下所示:
data-vesselname="CC CHÂTEAU D'IF"
这是ajax调用:
$.ajax({
url: 'api/searchVoyageInfo.php',
type: 'POST',
data: '',
dataType: 'html',
success: function(data, textStatus, jqXHR){
var jsonObject = JSON.parse(data);
var table = $('#example1').DataTable({
"data": jsonObject,
"columns": [{
"data": "",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol)
{
$(nTd).html("<a href='#' title='Edit Account' class='modAccount'
data-vesselname='"+oData.VESSEL_NAME+"'>Edit</a>");
}
},
{ "data": "ANOTHER_COLUMN" },
{ "data": "ANOTHER_COLUMN" },
// SEVERAL MORE COLUMNS
]
});
我删除了很多此问题不需要的代码。您可以在上方看到data-vesselname属性。问题似乎在那里发生。
我尝试执行以下操作:
data-vesselname='"+escape(oData.VESSEL_NAME)+"'
但是在检查元素时,我看到了:
data-vesselname="CC%20CH%C2TEAU%20D%27IF"
答案 0 :(得分:4)
您需要对附加字符串中的引号进行转义。您可以手动执行此操作,也可以让jQuery为您执行此操作:
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from six import StringIO
def convert_pdf_to_txt(path):
rsrcmgr = PDFResourceManager()
retstr = StringIO()
codec = 'utf-8'
laparams = LAParams()
device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
fp = open(path, 'rb')
interpreter = PDFPageInterpreter(rsrcmgr, device)
password = ""
maxpages = 0
caching = True
pagenos=set()
for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True):
interpreter.process_page(page)
fp.close()
device.close()
str = retstr.getvalue()
retstr.close()
return str.replace("\\n","\n")