【问题标题】:Ajax 404 error not found未找到 Ajax 404 错误
【发布时间】:2015-12-17 17:42:48
【问题描述】:

我遇到了 ajax 调用问题。

这是我使用 ajax 调用 http://www.cholokhai.com/resturant/test-demo/ 的地方

我已在页脚文件中包含脚本

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

ajax调用代码为:

jQuery("#next_button").click(function(e){
        jQuery(".fetch_data").hide();
        jQuery(".booking_confirm").show();

        var selected_date = jQuery("#selected_date").text();
        var selected_persons = jQuery("#selected_persons").text();
        var selected_discount = jQuery("#discount_time").text();
        var selected_price = jQuery("#discount_price").text();

        var filled_name = jQuery("#selected_name").val();
        var filled_email = jQuery("#selected_email").val();
        var filled_phone = jQuery("#selected_phone").val();

        var postData = 'name='+filled_name+'&email='+filled_email+'&phone='+filled_phone+'&date='+selected_date+'&persons='+selected_persons+'&time='+selected_discount+'&discount='+selected_price;
        jQuery.ajax({
            url : "http://www.cholokhai.com/ajax",
            type: "POST",
            data : {v:postData},
            dataType: 'json',
            success: function(html)
            {
                jQuery(".booking_confirm").show();

            }
        }); 

        return false;
    });

当我在数据中使用变量而不是字符串时,例如:数据{名称:填充名称,电子邮件:填充电子邮件} 我收到 404 错误。

我不知道为什么它不起作用。 请帮我解决这个问题。 谢谢。

【问题讨论】:

标签: php jquery ajax wordpress


【解决方案1】:

您正在使用查询字符串参数创建适合 URL 的字符串,而您需要传递一个 json 对象。

您可以手动创建它,也可以解析一个对象。底线不是 JSON 字符串。看看这样的东西:How can I create a specific JSON string?,它应该会有所帮助

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-14
  • 1970-01-01
  • 1970-01-01
  • 2014-07-04
  • 2018-05-03
  • 2015-09-19
相关资源
最近更新 更多