【发布时间】:2013-02-11 15:18:39
【问题描述】:
我喜欢使用 Ajax 调用来检索字符串,但我的响应中不断收到整个 html 页面。
获取字符串的方法是什么?
$.ajax({
url: '{$domainpath}{$language}/reservations/updatestartdates',
data: {property:property,stayduration:stayduration},
type: 'POST',
dataType: 'json'
}).done(function(response){
alert(response);
});
private function updateAvailableStartDates(){
if(isset($_POST['property']) && !empty($_POST['property']) && isset($_POST['stayduration']) && !empty($_POST['stayduration'])){
$property = $_POST['property'];
$stayduration = $_POST['stayduration'];
}
//handle code
echo json_encode('only this string');
}
【问题讨论】:
-
如果是 AJAX 请求,您只需要回显 字符串
-
@DipeshParmar 有什么用?
-
将更新函数放在页面内容输出之前,并在
echo之后添加exit;,这样如果POST请求匹配等则退出。