search

Home  >  Q&A  >  body text

javascript - Problem with ajax not being able to obtain data?

$(oFind).bind('click',function(){
        var oKeyword = $('.locating').val();
        if( oKeyword != '' ){
            $.ajax({
                type:"post",
                async:true,
                url: "{:U('Reply/index')}",
                data:{keyword:oKeyword},
                success:function(){
                    $(oZs).fadeOut("fast");
                    $(oCx).fadeIn("fast");
                }
            });
        }
    });

oFind is a button. After binding a click event to it, send an ajax request to the background and check the console that everything is normal. There are no errors in the parameters and URL.

<?php
namespace Home\Controller;
use Think\Controller;

class ReplyController extends CommonController {
    public function index(){
        if($_POST){
            
            echo "ddd";

        }
 
     }
}

But it just can’t print out ddd? Can you help me find out what’s wrong?

天蓬老师天蓬老师2853 days ago693

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-27 17:44:15

    Sister, you don’t have a console, how can you print? success:function(){

                $(oZs).fadeOut("fast");
                $(oCx).fadeIn("fast");
            }  改成  success:function(data){
                console.log(data);
                $(oZs).fadeOut("fast");
                $(oCx).fadeIn("fast");
            }

    reply
    0
  • 阿神

    阿神2017-05-27 17:44:15

    Ajax is not used like this. You pass the value, but if you echo something in the index, it cannot be seen on the other side.
    You set up a success callback and receive data processing here.
    I prefer json For transmission, if you use json, you can echo json_encode your data in the controller

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-27 17:44:15

    This is embarrassing. Isn’t the returned data a return? ? ? ? ? ? ? ? ? ? Forgive my ignorance

    reply
    0
  • Cancelreply