jQuery ajax() vs get()/post()

前端 未结 3 2073
鱼传尺愫
鱼传尺愫 2020-12-09 02:21

Let\'s say I want to execute a PHP script. Which way is better?

This:

$.ajax({
    type: \"GET\",
    url: \"php-script.php\",
    dataType: \"script         


        
3条回答
  •  有刺的猬
    2020-12-09 02:28

    $.get() is just a shortcut for an $.ajax() call of type "GET".

    To Elaborate $.get() just calls $.ajax() in the background. Its a shortcut kind of like what $(function(){}) is to $(document).ready(function(){}). Common use cases for $.get is for a quick and simple get, $.ajax should be used if you need to do something a bit more complex or if you need the extra flexibility.

提交回复
热议问题