【问题标题】:what is response in success: function(response) in ajax什么是成功响应:ajax 中的函数(响应)
【发布时间】:2016-03-27 14:13:18
【问题描述】:

我不确定我做的是否正确。我正在为 ajax 'GET' 请求传递一个 URL,并且 URL 有一些查询参数(?abc='a')。但是当我成功执行console.log(response)时:function(response){console.log(response)}。响应不包含abc值。

【问题讨论】:

  • 您能提供有问题的代码吗?如果我们有一些代码可以查看,答案会更容易。
  • 您为什么希望 response 包含 request 参数?
  • "什么是成功响应:ajax 中的函数(response)" This is perfectly well explained in the documentation.
  • 我们不知道您在服务器上处理这些查询参数或服务器返回什么。如果没有以某种方式包含它们的服务器端脚本,这些参数将不会成为响应的一部分。请显示所有相关代码

标签: jquery ajax url


【解决方案1】:

我将向您展示一个在控制台数据上使用 ajax 显示的示例:

<script type="text/javascript">
    //this the DOM
    $(function(){

        $('body').on('click', '.action_button', function() {
            $x = {
                key:'show',
                values:$('.values').val()
            }; $.post('ajax.php', $x, function(response) {
                console.log(response);
            });
        });

    });
</script>


<?php 
    //your php file in ajax.php (another file)
    $key = $_POST['key'];

    switch ( $key ) :
        case 'show' :
            $values = $_POST['values'];
            echo $values;
        break;
    endswitch;
 ?>

HTML 在这里

<input type="text" class="values" placeholder="Give me some values">
<input type="button" class="action_button" value="Click me for show the links">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2021-01-11
    • 2017-02-25
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多