json 문자열을 가져 오는 ajax 요청이 있는데 어떤 이유로 "정의되지 않음"을 반환하기 시작했습니다. JSON 문자열은 유효한 JSON을 반환하지만 작동하지 않습니다!값을 반환하지 않는 아약스 요청
Ajax 요청 :
if (editSeq) {
$.ajax({
url: './json/admin/getData.php',
type: 'POST',
async: false,
data: { SEQ: editSeq },
dataType: 'json',
success: function (data) {
var HTML = data.HTML;
$('#blankform').append(HTML);
alert(HTML);
}
});
JSON : 이것은 내 JSON 응답입니다
<?php
include("../../includes/db.php");
$SEQ = $_POST["SEQ"];
$sth = sqlsrv_query($conn,"SELECT HTML from TBL_DATA WHERE Sequence = " . $SEQ);
$rows = array();
while($r = sqlsrv_fetch_array($sth,SQLSRV_FETCH_ASSOC)) {
$rows[] = $r;
}
if($sth === false)
{
echo "Error in query preparation/execution.\n";
die(print_r(sqlsrv_errors(), true));
}
print json_encode($rows);
?>
: 당신은에서 재산 "HTML을 '겟하려고 var HTML = data.HTML;
와
[
{
"HTML": " \n\n<div id=\"div_143\" style=\"width: 300px; white-space: nowrap; padding-right: 50px; left: 60px; top: 48px;\" class=\"ui-resizable ui-draggable ui-resizable-disabled ui-state-disabled\" aria-disabled=\"true\"><label> Incident # <input type=\"text\" style=\"width:100%;\" id=\"input_143\" role=\"textbox\" aria-autocomplete=\"both\" aria-disabled=\"false\" aria-readonly=\"false\" aria-multiline=\"false\" class=\"jqx-widget-content jqx-widget-content-web jqx-input jqx-input-web jqx-widget jqx-widget-web jqx-rc-all jqx-rc-all-web\" placeholder=\"\" disabled=\"disabled\"><\\/label><div class=\"ui-resizable-handle ui-resizable-e\" style=\"z-index: 90;\"><\\/div><div class=\"ui-resizable-handle ui-resizable-w\" style=\"z-index: 90;\"><\\/div><div class=\"ui-resizable-handle ui-resizable-sw\" style=\"z-index: 90;\"><\\/div><div class=\"ui-resizable-handle ui-resizable-ne\" style=\"z-index: 90;\"><\\/div><div class=\"ui-resizable-handle ui-resizable-nw\" style=\"z-index: 90;\"><\\/div><div class=\"ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se\" style=\"z-index: 90;\"><\\/div><\\/div>"
}
]
먼저 PHP에서 매개 변수화 된 쿼리를 사용하십시오! http : // stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give -me-death.html – CenterOrbit
json은 PHP 측에서 어떤 모습입니까? –
인쇄 대신 에코를 사용해보십시오 ....? –