2013-12-18 15 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

相关问题