Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:46:20+00:00 2026-05-31T02:46:20+00:00

I have function: function get_playlist(){ var result = jQuery.ajax({ url: ‘<?php echo admin_url(‘admin-ajax.php’); ?>’,

  • 0

I have function:

    function get_playlist(){    

        var result = jQuery.ajax({
            url: '<?php echo admin_url('admin-ajax.php'); ?>',
            type: 'post',
            dataType: 'json',
            data: {
                action: 'getrandommp3',
                nonce:'<?php echo wp_create_nonce( 'randmp3' ); ?>'
            },
            success: function(response) {
                console.log(response); // All OK!
                window.response = response;
                var customvar = response;
                return response;
            }               
        });
        console.log(window.response); // undefined
        console.log(result.responseText); //undefined
        console.log(customvar); //undefined
        return window.response; // returning undefined
    }

I need to return json variable from function. Inside success: function(response) { responce have needed content. But outside of Jquery.ajax i have problems…

This code needed for jquery mp3 player…

var playlist = get_playlist(); 
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options); 
myPlaylist.shuffle(true, true);

Thank you for help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:46:21+00:00Added an answer on May 31, 2026 at 2:46 am

    This is the way AJAX works (asynchronously). The console.log statements outside of the success event handler are executed before the response has been returned (so nothing has been assigned to window.response yet). Put the code that relies on the AJAX response inside the success event handler.

    Alternatively, you could make the request synchronous, but that’s usually not what you want as it can lock the browser until the response is returned.

    Update (see comments and edit to question)

    As I mentioned previously, you need to put all code that relies on the AJAX response inside the ready event handler:

    function get_playlist(){    
        var result = jQuery.ajax({
            //Other AJAX options removed
            success: function(response) {
                var myPlaylist = new jPlayerPlaylist(cssSelector, response, options); 
                myPlaylist.shuffle(true, true);
            }               
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function function get_last(){ $.ajax({ url:'fronta.php?get_last&last=1', success:function(data) { var last = parseInt(data);
Ok, I have this code: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script type=text/javascript> function get()
I have a via with some jQuery function to get value from HTML element
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
var url = 'http://gdata.youtube.com/feeds/api/playlists/18508B7EDC293770?v=2&alt=json'; $.ajax({ url: url, cache: false, data: , type: GET, dataType:
I have a function which sends specified form data to a php processing page.
This is what I have: function get_bad_changelist_authors() { var changelistAuthorDivs = $('div.bad_changelist_author'); var changelistAuthors
Here I have some function to read my table <?php public function get_all_record($table, $fields
I have: function send(){ $.get(/site/send.php, function(data){ alert(data); } } In site/send.php I have: sleep(1000)
I have a function that get the current weeknumber from the given date e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.