0

I have some data from DB then I need to load. Something like this

$.ajax({
    type: "POST",
    url: "something.aspx",
    data: "{ 'something': 'something'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(res) {}
});​

I want returning string res.d to be added to var a, how this can be achieved.

$(document).ready(function () {
    var a =
});

Basically I am using xDHTML schedule unit view. Schedule units needs to be loaded on page load. So how to ad string from DB to var

1
  • what does your .net code look like? Commented Feb 16, 2012 at 14:10

1 Answer 1

3
var a = null;

$(document).ready(function () {
    $.ajax({
        type: "POST",
        url: "something.aspx",
        data: "{ 'something': 'something'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) {
            a = res;
        }
    });​
});

Should do it? Did you need the ASP part?

Sign up to request clarification or add additional context in comments.

6 Comments

I already tried that. When I put alert(a) below a = res I got good data, but when I put alert(a) after $.ajax({});​ I will get null
I edited my script, this should work since a is now at global scope.
Same thing :( inside $.ajax({}) everything is ok, but after it is constantly null. I don't know I will try tu put rest of code in success: function(res) {}
I found this that real problem is link is actually that var a = null; is not waiting for success: function(res)
AJAX calls are asynchronous (asynchronous javascript and xml). You can set it to Synchronous if you need to block the thread until success returns, but I wouldn't advise it. If you need it to by synchronous, set async = false in the options of the ajax() call.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.