【发布时间】: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 错误。
我不知道为什么它不起作用。 请帮我解决这个问题。 谢谢。
【问题讨论】:
-
你做错了。不要以这种方式包含 jQuery。它会引起各种各样的问题。使用正确的方法。请在此处查看我的答案:stackoverflow.com/questions/34321767/…
-
404 error表示url错误... -
404 表示找不到页面。如果cholokhai.com 是您应用程序的基本 url,您应该只使用 : url : "/ajax"
-
WordPress 中的 AJAX 是经过专门设计的。我强烈建议您阅读这篇文章:premium.wpmudev.org/blog/using-ajax-with-wordpress 和/或这篇文章:code.tutsplus.com/tutorials/…
-
您正在格式化要发送的数据,就好像它是 url 的一部分一样。您应该将其作为序列化的 json 对象发送。