[jQuery] jQuery.ajax(options)、$.ajax のメモ

jQuery の $.ajax メソッドの引数や、success, error, complete などに指定する引数をよく忘れてしまうのでメモ。

jQuery 1.7 までの $.ajax

$.ajax({
  url: 'http://api.example.com/v1/posts',
  type: 'POST',
  dataType: 'HTML',
  data: {
    id: '123'
  },
  success: function(data, statusText, xhr){
    if (xhr.status === 200) {
      // 成功時の処理
    } else if (xhr.status === 302) {
      // HTTPステータスコードによって、処理を分岐
 
      // 302 でリダイレクトさせたり
      location.href = 'http://example.com/redirect';
    }
  },
  error: function(xhr, statusText, error) {
    // エラー処理
  },
  complete: function(xhr, statusText){
    // 共通処理
  }
});

jQuery 1.8 以降の $.ajax

success, error, complete が .done, .fail, .always に変更されているようです。

これについては、いつか更新します。


参考情報

jQuery.ajax()のまとめ: 小粋空間

jQuery モダンAjaxな書き方を目指して 〜Deferredを使ったAJAX〜 – Hack Your Design!

jQuery.ajax(options) – jQuery 日本語リファレンス

jQuery.ajax() | jQuery API Documentation

[Xcode5][CocoaPods] Apple Match-O Linker Error : ld: library not found for -lPods

Xcode5にアップデートすると、今まで通っていたビルドが失敗するようになりました。

エラーメッセージ その1

xcode5-cocoapods-error1

Apple Match-O Linker Error
Linker command failed with exit code 1 (use -v to see invocation)

エラーメッセージ その2

xcode5-cocoapods-error2

ld: library not found for -lPods
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
Library not found for -lPods
Linker command failed with exit code 1 (use -v to see invocation)

気になるWarningメッセージ

Pods was rejected as an implicit dependency for 'libPods.a' because its architectures 'armv7 armv7s' didn't contain all required architectures 'armv7 armv7s arm64'

CocoaPodsのアップデートで解決

cocoapods をアップデートします。

gem update cocoapods

アップデート後、改めて pod install します。

pod install

再度、ビルドすると正常にビルド完了しました。


参考情報

Objective-C – CocoapodsとXcode5の組み合わせでエラー出た+解決した – Qiita [キータ]

[iOS][Xcode] ビルドエラー「While reading … pngcrush caught libpng error」の解決方法

iOSアプリのビルドエラー「While reading … pngcrush caught libpng error」の解決方法をメモ。

CopyPNGFile エラーメッセージ

Command  emitted errors but did not return a nonzero exit code to indicate failure

CopyPNGFile エラーの解決方法

Project Target -> Build Phases -> Copy Bundle Resources にて、エラーが発生している画像ファイル名が重複して登録されている場合、片方だけ削除します。

Xcode-Copy_Bundle_Resources

以上です。


参考情報

ビルドエラー「While reading … pngcrush caught libpng error」への対処方法 – 甘いものが好きです

iphone – Not a PNG filCommand copypng emitted errors but did not return a nonzero exit code to indicate failure – Stack Overflow

[iOS] ビルドエラー(CopyPNGFile Error…)の対処法: ものづくりログ

[Xcode] C++11 Standard Library : libc++ (LLVM C++ standard library with C++11 support)

iOSアプリ開発で、QRコード用のライブラリ「ZXing」を使う場合にそのままではビルドが通りませんでした。

ビルド時に LLVM C++ を利用する必要があるそうで、その設定をメモ。


LLVM C++ の利用手順

Podsプロジェクトにて、Pods-ZXingを選択した状態で、

  • Build Settings
    • Apple LLVM 5.0 – Language – C++
      • C++ Standard Library

の項目を、Compiler Default から libc++(LLVM C++ standard library with C++ 11 support)に変更すればOKです。

Xcode-LLVM-Cpp


参考情報

XCodeでC++11を使う方法 – 亀岡的プログラマ日記

WordPress サーバの移行手順

WordPress サイトを旧サーバから新サーバへ移行したので、手順をざっくりご紹介します。

WordPress | ワードプレス

続きを読む

[WordPress]「古いプラグインを削除できませんでした。」の解決方法

WordPressで、プラグインを削除しようとしたら「古いプラグインを削除できませんでした。」エラーが発生しました。

WordPress | ワードプレス

続きを読む

[Linux] hostname(ホスト名)の変更方法

Linux で hostname(ホスト名)を変更する方法をご紹介します。

Linux

続きを読む

[iOS] Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID

iOS アプリにて、Code Sign error が発生してビルドできなかったときの解決方法をメモ。

エラーメッセージ

Code Sign error:
No matching provisioning profile found:
Your build settings specify a provisioning profile with the UUID “XXXXXXXX-2006-4254-8F70-E0316170D737”,
however, no such provisioning profile was found.
Warning: Multiple build commands for output file xxxx
CodeSign error: code signing is required for product type ‘Application’ in SDK ‘iOS 7.0’

解決方法

project.pbxproj の該当する PROVISIONING_PROFILE の行を削除すればビルドが通りました。


参考情報

project.pbxprojの怪 | 株式会社LIG

[MongoDB] バックアップ mongodump とリストア mongorestore

MongoDB のバックアップ mongodump とリストア mongorestore の方法をご紹介します。

MongoDB | モンゴディービー

続きを読む

[jQuery] チェック済みの checkbox の値を取得して配列へ格納する方法

jQuery で、チェック済みの checkbox の値を取得して配列へ格納する方法をメモ。

<input type="checkbox" name="seasons" value="spring"> 春
<input type="checkbox" name="seasons" value="summer"> 夏
<input type="checkbox" name="seasons" value="autumn"> 秋
<input type="checkbox" name="seasons" value="winter"> 冬

チェックされた checkbox の値を取得して、配列に格納するコードは下記の通りです。

var checkedSeasons = [];
$('[name="seasons"]:checked').each(function(){
  checkedSeasons.push($(this).val());
});

参考情報

jQueryでチェックされたcheckboxの値を取得して配列に格納する方法、また、配列をcheckboxの値に設定する方法 – knt45の日記