2015-12-17 243 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是我的自定義帖子類型。和測試演示是我的職位 –