2013-12-18 22 views
0

對不起,我的條件,因爲他們是不正確的,但我有一個php函數,我要與ajax互操作,所以我可以使用PHP函數來獲得jquery變量的值。我怎樣才能設置一個jQuery的var是另一個jQuery的ajax函數回調

所以,現在我只是在我已經收到了Ajax回調,並想設置jQuery變量爲我回來的響應值。這裏是我的代碼爲例:

$(document).ready(function() { 


    $('body').videoBG({ 
     position:"fixed", 
     zIndex:0, 
     mp4:'', //This is where I want to use the ajax response value 
     opacity:1, 
    }); 

}) 

     jQuery.ajax({ 
      type : "POST", 
      url  : "index.php", 
      data : { 
         request : "getvideo_Action" 
         }, 
      success : function(response) { 
            alert(response); 
       //Do my response stuff 
          } 
     }); 

所以基本上我想要做的是設置'MP4的VAR(或者是財產?)有,我從響應中獲得的價值。任何人都可以幫我解決這個問題嗎?謝謝。

+0

你將需要移動需要Ajax請求的Ajax請求的成功裏面的響應代碼。 –

+0

http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call?rq=1 – Blazemonger

回答

1

你可以把整個事情的成功,函數內部,就像這樣:

jQuery.ajax({ 
    type: "POST", 
    url: "index.php", 
    data: { 
     request: "getvideo_Action" 
    }, 
    success: function (response) { 
     $('body').videoBG({ 
      position: "fixed", 
      zIndex: 0, 
      mp4: response, 
      opacity: 1 
     }); 
    } 
}); 
+0

「opacity:1」後面有一個尾隨逗號需要刪除或IE將有問題...除此之外,這是正確的解決方案。 – FastTrack

+0

刪除了逗號。感謝您的領導! –

+0

我不認爲我可以把整個功能放在那裏。太好了,謝謝你的幫助。這是非常讚賞。 :) – user1632018

相關問題