无法通过ajax从php函数获得响应

时间:2022-10-08 17:34:31

I want to display emoticon by click on a tab. Here my browser display: ajax sent data to smileysmore.php as action:smileysboxmore Sid:888 but cannot display any response data.

我想通过单击选项卡来显示表情符号。这里我的浏览器显示:ajax将数据发送到smileysmore.php作为动作:smileysboxmore Sid:888但无法显示任何响应数据。

I am working new with php function. Please give me a guideline.

我正在使用php功能。请给我一个指导。

Html:

<ul class="nav nav-tabs">
    <li class="active"><a href="#sectionA">A</a></li>
    <li><a class="sm2" href="javascript: void(0)">B</a></li>
</ul>
<div class="tab-content">
    <div id="sectionA">
    <div id="sectionB">
</div>

Ajax:

$(document).ready(function(){
    $('li').on("click", 'a.sm2', function(e){
    var id = 888;
        $.ajax({
        type: "POST", 
        url: "../smileysmore.php", 
        data: "action=smileysboxmore&Sid="+ id,
            complete: function(data){
            $('#sectionA').hide();
            $('#sectionB').fadeIn().html(data);
            }
        });
    });
});

smileysmore.php

function smileysboxmore($Sid){
echo'<img src="../smile.gif" alt=":)" class="embtno" id="'.$Sid.'" />
     <img src="../sad.gif" alt=":(" class="embtno" id="'.$Sid.'" />
     <img src="../cool.gif" alt="B-)" class="embtno" id="'.$Sid.'" />';
}

1 个解决方案

#1


2  

in your ajax change complete to success

在你的ajax改变完成成功

$(document).ready(function(){
    $('li').on("click", 'a.sm2', function(e){
    var id = 888;
        $.ajax({
        type: "POST", 
        url: "../smileysmore.php", 
        data: "action=smileysboxmore&Sid="+ id,
            success: function(data){
            $('#sectionA').hide();
            $('#sectionB').fadeIn().html(data);
            }
        });
    });
});

and in smileysmore.php

并在smileysmore.php

smileysboxrepmore($_POST['Sid']);
function smileysboxrepmore($Sid){
echo'<img src="../smile.gif" alt=":)" class="embtno" id="'.$Sid.'" />
     <img src="../sad.gif" alt=":(" class="embtno" id="'.$Sid.'" />
     <img src="../cool.gif" alt="B-)" class="embtno" id="'.$Sid.'" />';
}

#1


2  

in your ajax change complete to success

在你的ajax改变完成成功

$(document).ready(function(){
    $('li').on("click", 'a.sm2', function(e){
    var id = 888;
        $.ajax({
        type: "POST", 
        url: "../smileysmore.php", 
        data: "action=smileysboxmore&Sid="+ id,
            success: function(data){
            $('#sectionA').hide();
            $('#sectionB').fadeIn().html(data);
            }
        });
    });
});

and in smileysmore.php

并在smileysmore.php

smileysboxrepmore($_POST['Sid']);
function smileysboxrepmore($Sid){
echo'<img src="../smile.gif" alt=":)" class="embtno" id="'.$Sid.'" />
     <img src="../sad.gif" alt=":(" class="embtno" id="'.$Sid.'" />
     <img src="../cool.gif" alt="B-)" class="embtno" id="'.$Sid.'" />';
}