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

  • SEARCH
  • Home
  • 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 9246223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:26:45+00:00 2026-06-18T09:26:45+00:00

I am having a problem with the following Jquery code: function isAuthorised() { $.post(Action/Controller)’,

  • 0

I am having a problem with the following Jquery code:

function isAuthorised() {
  $.post("Action/Controller")', function (data) {
    return data;
  });
}

I have tested the return value from my MVC controller and that is fine. But when I check the authorisation with the following:

function onLoad() {
  var result = isAuthorised();
  alert(result); // undefined
  if (!result) 
    // redirect
}

the returned value is undefined. I have seen a similar post here and think this may be a problem with encapsulation, but the difference being that I need to return the value that is retrieved from JQuery.post().

Edit: Ok, I don’t want to do the redirect inside the callback, so I am now attempting to return the value by using .Ajax and setting Async to false. I am now returning [Object object] with the code below. Could someone explain the difference now I am setting async to false and help me return the value?

var request = $.ajax({
        url: 'Action/Controller',
        type: 'post',
        async: false
      });

      var result = request.done(function (data) {
        return data;
      });
      alert(result); // [Object object]
  • 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-18T09:26:46+00:00Added an answer on June 18, 2026 at 9:26 am

    You should check the dataType parameter for the jQuery ajax call. Depending on the return value you want to have, it might be a good practice to explicitly set the dataType (xml, json, text, …)

    If you are giving back a json, it will be converted into a JavaScript object. From your alert I’m assuming that to be the case.

    Try this mod for getting a string back:

    var request = $.ajax({
        url: 'Action/Controller',
        type: 'post',
        dataType: 'text',
        async: false
    });
    
    alert(request.responseText); // [now it will be outputted as text]
    

    In a sync ajax call request will be filled to be an object, so you have to use one of it’s properties to extract the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
I am having problem with the following JQuery code: $(object).hover(function(e){ alert('Flash Here'); }); I
I am having an odd problem with jQuery 1.5.2 in Chrome. I have code
We are having 2 problem with jquery. Please have a look at the following...
I am having the following problem: a) I have a UNIX build environment set
I'm having a problem with the following code foreach ($ex in (foo, bar, baz))
I have been having the following problem, i think it's probably due to the
I have the following jQuery snippet which should replace a code such as [Button]
I am having a problem with getting my JQuery javascript code to apply to
I am using JQuery Mobile Datebox as I am having the following problem. I

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.