0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

非同期通信

0
Last updated at Posted at 2026-02-16
title.js
function myFunction(){
   var deferred = $.Deferred()
   $.ajax({
      url:'',
      dataType; 'Json',
      type; 'POST', //jQuery1.9以降は非推奨なので→method:'POST'
      data: {}
   })
   .done(function(){
      deferred.resolve()
   })
   .fail(function(){
      deferred.reject()
   })
   return deferred.promise()
}

myFunction().done( result => console.log('非同期処理が完了しました')
myFunction().fail( result => console.log('非同期処理が失敗しました')

title.js

function myFunction(){
   return $.Deferred(function(deferred){
   $.ajax({
      url:'',
      dataType; 'Json',
      type; 'POST', //jQuery1.9以降は非推奨なので→method:'POST'
      data: {}
   })
   .done(function(){
      deferred.resolve()
   })
   .fail(function(){
      deferred.reject()
   })
   }).promise()
}

myFunction().done( result => console.log('非同期処理が完了しました')
myFunction().fail( result => console.log('非同期処理が失敗しました')

contentType: サーバーに送信するデータの形式を指定します。

dataType: サーバーから返されるデータの形式を指定します。

ajax通信がエラーになった時に見直す。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?