我正在尝试将数据发送到php文件,并且我正在使用post并获取基于它是post还是get接收数据。问题是get正在工作,我单击以通过post接收数据,我没有收到任何东西。
php 代码进程在到达 GET 时停止,然后我发送 I POST,它没有响应它。我可以看到 ajax 发送数据,但当 GET 在 php 文件中工作时,php 没有收到它。
PHP代码:
if($_POST['id']){ show data}elseif{$_GET['id']{ get data}
jquery ajax:
// Youtube videos:
$(function() {
$('.image').click(function() {
var id = $(this).attr('id');
var msgbox = $("#video_status");
if(id.length > 5) {
$("#Video_status").html('<img src="assets/imgs/loading.gif" alt="loading ... " />');
$.ajax({
type: "POST",
url: "my_video.php",
data: 'id='+ id ,
cache: false,
success: function(msg){
$('#Video_status').html(msg);
if(msg ) {
msgbox.html(msg);
}else{
msgbox.html(msg);
}
}
});
}
return false;
});// End of youtube videos.
$(function() {
var loader = $("#Video_status").html('<img src="assets/imgs/loading.gif" alt=" loading ... " />');
var VideoWrap = $('#VideoWrap');
loader.fadeOut(1000);
$.get('my_video.php', '', function(data, status){
VideoWrap.fadeOut(1000);
VideoWrap.html(data);
VideoWrap.fadeIn();
});
return false;
});
});// get youtube video.
第一次使用 isset
进行检查
if(isset($_POST['id']))
{
//to show data echo/print something
echo $_POST['id'];
}
elseif(isset($_GET['id']))
{
//get data
}
试试这个
if($this->getRequest()->isPost()) {
}
if($this->getRequest()->isGet()) {
}
为什么不是这样的东西?
$postOrGetVar= $_GET['paramname'] ? $_GET['paramname'] : ($_POST['paramname'] ? $_POST['paramname'] : 'Param not sent via Post nor Get');
简单、易读且容易。