【问题标题】:Passing JSON over .ajax() with jQuery [closed]使用 jQuery 通过 .ajax() 传递 JSON [关闭]
【发布时间】:2011-01-19 11:01:22
【问题描述】:

我无法理解如何创建一个 jQuery .ajax 函数来将数据(多个变量)发布到我的 php 页面,然后从 PHP 页面返回信息。

$('#RoomCode').change(function() 
{
    //alert($(this).attr('value'));
    var RoomCode = $(this).attr('value');

    //Create JSON Object to send to Ajaxdo
    var toAjax = { "GetRoomCodeParams": [ { "GetRoomCode" : "1", "RoomCode" : RoomCode } ]};
    alert(toAjax);
    $.ajax({ 
        url: "ajaxdo.php",  
        type: "POST", 
        dataType: json,
        cache: false,        
        data toAjax,
        success: function (response) { 

            alert(response);
            $('#RoomInfoCode', '#RoomClassCode').fadeOut();     
            $('#RoomInfoCode').empty();
            $('#RoomInfoCode').fadeIn();    

        } 
    });    

});

编辑:感谢您指出缺少的冒号:(现在附加到代码中)

现在我在属性列表成功后收到缺失的 }:(响应){}

我已经清除了以下内容的修改成功,但仍然收到此错误:

success: function (response) { } 

【问题讨论】:

  • 你需要一个 ':' 在 data prop 之后;)
  • 解决了这个问题。现在我在属性列表成功后丢失{:函数(响应){

标签: jquery ajax json post


【解决方案1】:

你有一个错字:

data toAjax,

应该是

data: toAjax,

【讨论】:

    【解决方案2】:

    你漏掉了一个冒号,试试

    data:toAjax,
    

    而不是

    data toAjax,
    

    【讨论】:

    • 知道为什么我会遇到这个其他错误吗?
    猜你喜欢
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多