我被困在这里了。
我尝试在选择div时触发ajax,然后获得JSON响应。我所能返回的只有错误代码,我不确定为什么。这是简化的版本(仍然得到与实际相同的响应)。也许还有更好的办法?谢谢你的帮助。
jquery:
<html lang="en">
<meta charset="utf-8">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<style>
#selectable .ui-selecting { background: #FECA40; }
#selectable .ui-selected { background: #F39814; color: white; }
#selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
</style>
<script>
$(function(){
$("#selectable").selectable({
selected : function(event, ui) {
if($(ui.selected).hasClass('ui-widget-content')){
var rptID = ($(ui.selected).val());
$.ajax(
{
type: "POST",
dataType: "json",
url: "hello2.php",
success: function( response )
{
alert(1);
},
error: function( error )
{
console.log(error);
}
} );
}
}
});
});
</script>
<body><ol id="selectable">
<li class="ui-widget-content" value=1 >Item 1</li>
<li class="ui-widget-content" value=2>Item 2</li>
<li class="ui-widget-content" value=3>Item 3</li>
</ol></body>
</html>php:
<?php
$json = array('hello' => 'hello');
header('Content-Type: application/json');
echo json_encode($json);
?>发布于 2014-08-19 23:36:51
php?>将导致PHP级的语法错误/警告,并且该语法错误输出可能会被标记到您的JSON输出的末尾,从而导致客户端上的JSON解析错误。
PHP代码块是简单的<?php ... ?>。
例如:
[marc ~]$ cat z.php
<?php
echo json_encode('foo');
php?>
[marc ~]$ php z.php
"foo"PHP Notice: Use of undefined constant php - assumed 'php' in /home/marc/z.php on line 3编辑-现在我看到OP编辑掉了php?>的东西...
https://stackoverflow.com/questions/25387275
复制相似问题