2016-12-06 18 views
5

我是新來的jQuery 3.以下是一個基本fiddle,使用jQuery以前版本的工作,但不使用jQuery 3jQuery的3苗條阿賈克斯基本的例子

$(function() { 
    $.ajax({ 
     url: '/echo/json', 
     type: 'GET', 
     dataType: 'json', 
     success: function(data) { 
      console.log(data) 
     } 
    }); 
}) 

工作在控制檯中,我得到這個錯誤:

jquery-3.1.1.slim.min.js:2 jQuery.Deferred exception: $.ajax is not a function TypeError: $.ajax is not a function

jquery-3.1.1.slim.min.js:2 Uncaught TypeError: $.ajax is not a function(…)

爲什麼?

+0

[剛剛看過了關於修改(https://jquery.com/upgrade-guide/3.0/#ajax) – GillesC

+0

你有沒有用jQuery文件 –

+0

連接@DavidJorHpan是當然的 –

回答

14

jQuery 3 slim版本不支持ajax。

按照release docs

Along with the regular version of jQuery that includes the ajax and effects modules, we’re releasing a 「slim」 version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code.

要使用.ajax方法,簡單地使用完整版本之一。

這裏的工作fiddle

+0

只需添加到:要替換原始提琴中的jquery slim,請單擊左側菜單上的External Resources以移除並添加jQuery資源。 (這不是馬上明白我如何刪除jQuery苗條) –

+0

謝謝!現在如此明顯...... –