最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Laravel 5.5 jQuery 3.3.1 ajax is not a function - Stack Overflow

programmeradmin3浏览0评论

I've been developing a callcenter app with twilio and laravel 5.5, I want to get webrtc capabilities in my app and for that i have to use ajax to make requests.

however i am getting the following warning:

jQuery.Deferred exception: $.ajax is not a function @http://localhost:8000/js/browser-calls.js:14:2 l@http://localhost:8000/js/jquery.js:2:29373 a/http://localhost:8000/js/jquery.js:2:2967

with the following error:

TypeError: $.ajax is not a function

I've searched high and low for solutions and I've tried the folowing:

  1. download jquery from the cdn to client and include it

  2. try the latest CDN <script src=".3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>

  3. Tested in edge, chrome, firefox
  4. check if I'm not accidentally using the slim build
  5. place everything in my app.blade.php's header below jquery instead of right before the </body>

<script src=".3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> <script type="text/javascript" src="//media.twiliocdn/sdk/js/client/v1.3/twilio.min.js"></script> <script type="text/javascript" src="{{ asset('js/browser-calls.js') }}"></script>

nothing has been able to resolve the issue, this is my ajax call

    /* get twilio token with AJAX request */
var clientName = $('#agent-name').data('name');
    $.ajax({
        type: 'POST',  
        url: '/twilio/generate-token', 
        data: {
            clientName: clientName,
        },
        success: function(data) {
            Twilio.Device.setup(data.token);
        }
    });

i also tried the $.post instead of $.ajax but it resulted in the same error.

$.post('/twilio/generate-token', {
    clientName: clientName,
    clientToken: this.clientToken
    }, function(data) {
        Twilio.Device.setup(data.token);
});

What the hell is causing the $.ajax function to not be recognized..

I've been developing a callcenter app with twilio and laravel 5.5, I want to get webrtc capabilities in my app and for that i have to use ajax to make requests.

however i am getting the following warning:

jQuery.Deferred exception: $.ajax is not a function @http://localhost:8000/js/browser-calls.js:14:2 l@http://localhost:8000/js/jquery.js:2:29373 a/http://localhost:8000/js/jquery.js:2:2967

with the following error:

TypeError: $.ajax is not a function

I've searched high and low for solutions and I've tried the folowing:

  1. download jquery from the cdn to client and include it

  2. try the latest CDN <script src="http://code.jquery./jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>

  3. Tested in edge, chrome, firefox
  4. check if I'm not accidentally using the slim build
  5. place everything in my app.blade.php's header below jquery instead of right before the </body>

<script src="http://code.jquery./jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> <script type="text/javascript" src="//media.twiliocdn./sdk/js/client/v1.3/twilio.min.js"></script> <script type="text/javascript" src="{{ asset('js/browser-calls.js') }}"></script>

nothing has been able to resolve the issue, this is my ajax call

    /* get twilio token with AJAX request */
var clientName = $('#agent-name').data('name');
    $.ajax({
        type: 'POST',  
        url: '/twilio/generate-token', 
        data: {
            clientName: clientName,
        },
        success: function(data) {
            Twilio.Device.setup(data.token);
        }
    });

i also tried the $.post instead of $.ajax but it resulted in the same error.

$.post('/twilio/generate-token', {
    clientName: clientName,
    clientToken: this.clientToken
    }, function(data) {
        Twilio.Device.setup(data.token);
});

What the hell is causing the $.ajax function to not be recognized..

Share Improve this question edited Feb 7, 2018 at 10:19 Amit Gupta 2,8062 gold badges19 silver badges34 bronze badges asked Feb 7, 2018 at 9:42 Wouter Van HeesWouter Van Hees 512 silver badges8 bronze badges 3
  • The error implies that you're using the 'slim' branch of jquery, which does not have AJAX and several other features. You said you've tried to add a full version of jQuery, but ensure you only include that version, and have removed any previous ones. – Rory McCrossan Commented Feb 7, 2018 at 9:45
  • And make sure include jQuery before you include your js-code, so jQuery is available when your code is executed. – KungWaz Commented Feb 7, 2018 at 9:46
  • it apparently was caused by the app.js from laravel, if i load my local jquery and all the other scripts after the app.js it seems to work – Wouter Van Hees Commented Feb 7, 2018 at 10:03
Add a ment  | 

3 Answers 3

Reset to default 3

The jquery liberary was included before the app.js script from laravel itself, after i moved the jquery cdn below the defenition of app.js the problem was fixed

I had the same issue, but fixed it by adding this line:

<script src="https://ajax.aspnetcdn./ajax/jQuery/jquery-3.3.1.min.js"></script>

I faced same issue and got a better solution, than including a second jQuery. As I found out the app.js requires bootstrap.js.

In bootstrap.js the "jquery/dist/jquery.slim.js" is loaded, just change this to: "jquery/dist/jquery.min.js" and after repiling and loading page a few times the issue is solved in a cleaner way.

So problem was that the slim version of jQuery was loaded, which indeed does not contain any ajax feature.

发布评论

评论列表(0)

  1. 暂无评论