2015-12-17 245 views
0

我正面临ajax调用的问题。未找到Ajax 404错误

这是我LIMK这里我使用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; 
    }); 

当即时通讯使用变量不是字符串的数据,如:data {name:filled_name,email:filled_email} 即时通讯404错误。

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

+1

你做错了。不要以这种方式包含jQuery。它会造成各种问题。使用正确的方法。在这里看到我的答案如何做到这一点:http://stackoverflow.com/questions/34321767/wordpress-inline-js-cant-get-working/34322445#34322445 –

+1

'404错误'意味着''url'是错误的.. –

+0

404表示未找到页面。如果http://www.cholokhai.com是您应用程序的基础网址,则应该使用:url:“/ ajax” – DinoMyte

回答

0

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

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

+0

我使用ajax调用url http://www.cholokhai.com/resturant/test-demo/其中resturant是我的自定义帖子类型。和测试演示是我的职位 –