【发布时间】:2015-12-20 12:26:32
【问题描述】:
我不知道这几行代码有什么问题,在我之前的插入函数中它可以工作,但这个不行,请帮我弄清楚,因为它已经花了我一个小时了
my views(touristspot.blade.php)
<?php
foreach($data as $r){
echo "<input type='hidden' id='placeid' value='$r->placeid'>";
}
?>
<textarea id="comment"></textarea> <br>
<button type="submit" id="save" name="save">Comment</button>
<script type="text/javascript">
$("#save").click(function(e){
e.preventDefault();
var placeid = document.getElementById('placeid').value;
var comment = document.getElementById('comment').value;
$.ajax({
ur: "touristspot",
type: "POST",
data: {placeid:placeid,comment: comment},
success: function(data) {
//console.log(data);
}
});
});
</script>
my controller
public function addcomment(){
$details = Input::all();
$comments= new Comments;
$comments->placeid = Input::get('placeid');
$comments->comment = Input::get('comment');
$comments->save();
return View::make('content.touristspot');
}
my routes
Route::post('touristspot','UserController@addcomment');
【问题讨论】:
-
不应该是
ur:是url:? -
Ajax 也有失败和错误的功能,尝试借助这些功能进行调试
-
jqueery .ajax 有一个
error回调,很像success回调` - 请参阅api.jquery.com/jquery.ajax 的文档 -
也可以更短:
$.post("touristspot", {"placeid":placeid,"comment": comment},function(data) { console.log(data); }); -
使用 firbug 扩展调试错误原因
标签: javascript php mysql ajax laravel