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 8369773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:44:17+00:00 2026-06-09T13:44:17+00:00

function ajax_test(str1){ var url = "None" jq.ajax({ type:’post’, cache: false, url: ‘http://….’ + str1,

  • 0
function ajax_test(str1){ 
  var url = "None" 
  jq.ajax({
    type:'post', 
    cache: false, 
    url: 'http://....' + str1, 
    success: function(data, status, xhr){ 
      url=data; 
    }, 
    error: function (xhr, status, e) {  
    }, 
    async: true, 
    dataType: 'json' 
  }); 
  return url 
} 

How can I set the global variable url to be the returned success ajax data?

  • 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-06-09T13:44:19+00:00Added an answer on June 9, 2026 at 1:44 pm

    In Javascript, it is impossible for a function to return an asynchronous result. The function will usually return before the AJAX request is even made.

    You can always force your request to be syncronous with async: false, but that’s usually not a good idea because it will cause the browser to lock up while it waits for the results.

    The standard way to get around this is by using a callback function.

    function ajax_test(str1, callback){  
       jq.ajax({ 
         //... your options
         success: function(data, status, xhr){  
           callback(data);
         }
       });  
    }  
    

    and then you can call it like this:

    ajax_test("str", function(url) {
      //do something with url
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery AJAX function like this: $.ajax({ url: 'crud/clients.php', dataType: 'json', type:
In javascript I have the following: $.ajax({ url: /ajax/test, type: POST, dataType: html, data:
I have a jquery function in my script function test(){ $.ajax({ url: '/Customer/test' +
Could someone tell me if this: $.ajax({ url: 'test.html', success: function(data) { alert(Data Loaded:
function symbol_handler(){ fp.getForm().submit({ url:'/index.php/ajax/test_function', success:function(resp){ //how would i access attributes of the json object?
This is my ajax function: function ajax_call(call_method,data_to_send) { logger(function ajax_call. var data_to_send: ); logger(data_to_send);
I try to post the values from the input field with the jquery.ajax function
I want to test the following AJAX function my.var = true; my.method = function()
var ajax = { xmlHTTP: function() { xml = new XMLHttpRequest(); return xml; },
I have an anchor tag with a click event on it $('a').click(function(){ $.ajax({ url:

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.