0

Sorry for my terms incase they are incorrect, but I have a php function that I am going to interop with ajax so I can use a php function to get a value for a jquery variable.

So now I am just at the point where I have received the ajax callback and would like to set the jquery variable to the response value I got back. Here is my code as an example:

$(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
                            }
        });  

So basically what I want to do is set the 'Mp4' var(or is it property?) with the value that I get from the response. Can anyone help me out with this? Thanks.

user1632018
  • 2,485
  • 10
  • 52
  • 87
  • You would need to move the code that needs the response of the ajax request to inside the success of the ajax request. – Kevin B Dec 18 '13 at 19:49
  • http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call?rq=1 – Blazemonger Dec 18 '13 at 19:53

1 Answers1

1

You can put the entire thing inside the success function, like this:

jQuery.ajax({
    type: "POST",
    url: "index.php",
    data: {
        request: "getvideo_Action"
    },
    success: function (response) {
        $('body').videoBG({
            position: "fixed",
            zIndex: 0,
            mp4: response,
            opacity: 1
        });
    }
});
Magnus Engdal
  • 5,446
  • 3
  • 31
  • 50