我有一个ajax请求获取json字符串,但由于某种原因它已经开始返回“undefined”,json字符串确实返回有效的JSON,但它只是不工作!ajax请求不返回值
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:
<?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);
?>
这是我的JSON响应:
[
{
"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方面看起来如何? –
尝试回显而不是打印....? –