3 回答

TA貢獻1942條經(jīng)驗 獲得超3個贊
好的做法是這樣使用:
$.ajax({
type: "POST",
url: "/ajax/request.html",
data: {action: 'test'},
dataType:'JSON',
success: function(response){
console.log(response.blablabla);
// put on console what server sent back...
}
});
而PHP部分是:
<?php
if(isset($_POST['action']) && !empty($_POST['action'])) {
echo json_encode(array("blablabla"=>$variable));
}
?>

TA貢獻2003條經(jīng)驗 獲得超2個贊
<script type="text/javascript">
function returnwasset(){
alert('return sent');
$.ajax({
type: "POST",
url: "process.php",
data: somedata;
dataType:'text'; //or HTML, JSON, etc.
success: function(response){
alert(response);
//echo what the server sent back...
}
});
}
</script>

TA貢獻2039條經(jīng)驗 獲得超8個贊
<?php echo 'apple'; ?> 實際上,這是服務(wù)器上所需的全部內(nèi)容。
至于JS端,服務(wù)器端腳本的輸出將作為參數(shù)傳遞給成功處理程序函數(shù),因此您需要
success: function(data) {
alert(data); // apple
}
- 3 回答
- 0 關(guān)注
- 652 瀏覽
添加回答
舉報