0

这是我在控制器中的函数 function show_data() { return "this is me"; }

这是我的观点:

<html>
<head>
    <title>ajax call first time</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">                                               </script> 
    <script type="text/javascript">
    $(document).ready(function(){
        alert("hello");
        $.ajax({
            type:'POST',
            dataType: "text", 
            url:'elements/show_data',
            success:function(res){
            console.log(res);
                $('#response').html(res);
            },
            fail:function()
            {
                $('#response').html("done");
            }
        });
    });
    </script>
</head>
<body>
<div class="response" id="response" ></div>
<div class="container" id="container" ></div>
</body>
</html>

控制台说empty string returned 为什么?

4

1 回答 1

0

这就是我使用 $.ajax 的方式

$.ajax({
    type: 'POST',
    dataType: 'text',
    url: 'the/url',
    data: {data1: "value", data2: "value"}
}).done(function(res) {
    console.log(res);
});

您可能需要elements/show_data使用浏览器检查您的 url(使用 GET)以确保您的控制器正常工作。

于 2013-10-26T13:05:42.550 回答