2
我有以下腳本到一個新的價值添加到我的會話變量的數組,並告訴我varible完全實時會話如何完成加載條件,一個函數在jQuery中執行另一個函數?
(function ($) {
Drupal.behaviors.MyfunctionTheme = {
attach: function(context, settings) {
$('.add-music').click(function() {
var songNew = JSON.stringify({
title: $(this).attr('data-title'),
artist: $(this).attr('data-artist'),
mp3: $(this).attr('href')
});
var songIE = {json:songNew};
$.ajax({
type: 'POST',
data: songIE,
datatype: 'json',
async: true,
cache: false
});
var session;
$.ajaxSetup({cache: false})
$.get('/getsession.php', function (data) {
session = data;
alert(session);
});
});
}}
})(jQuery);
的問題是,POST運輸時間比調用GET ALERT不再那麼顯示未更新的會話變量。
有沒有辦法只在POST完成時纔將IF條件寄送回來I GET?
感謝
打敗我吧。你可能想要建議'.done()'方法取代'$ .ajax'的'success'選項 - '$ .ajax({})。done(function(){});' – Ian
success:function (){...});折舊,所以使用done:function(){...});.請務必在處理GET之前測試返回的值是否有效。 – radi8
你是對的!我已經更新了我的回答 – OpherV