3
$(document).ready(function () {
    $("button").click(function () {
        getData();
    });
});

function getData() {
    var promise = testAjax('example2.aspx');
    displaySTSummaryData(promise);
}

function testAjax(theURL) {
    var person = {
        Name: 'happy',
        age: '21'
    };
    return $.ajax({
        url: theURL,
        type: 'POST',
        data: person
    });
}

function displaySTSummaryData(x) {
    x.success(function result(data) {
        $("div").html(data);
    });
}

In the above code I am sending data to example2.aspx. I can use only jquery aspx ajax. How can i display details of (Person (being sent ) on example2.aspx.

Satpal
  • 132,252
  • 13
  • 159
  • 168
Happy
  • 86
  • 10

3 Answers3

0

I would erase displaySTSummaryData function and add:

function testAjax(theURL) {
     var person = { Name: 'happy', age: '21' };
     return $.ajax
     ({
         url: theURL,
         type: 'POST',
         data: person
         success: function(e){
             $("div").html(e);
         }
      });
}
  • Sorry for not making it clear. I can populate data in my example.aspx where ajax is defined. I need to display the same data in example2.aspx. – Happy Apr 25 '14 at 09:15
0

You can only call a static function in .aspx. Use like

function testAjax(theURL) {
    var person = {
        Name: 'happy',
        age: '21'
    };
    $.ajax({
        url: "example2.aspx/GetData",
        type: 'POST',
        data: person,
        success: function (data) {
            $("div").html(data);
        }
    });
}

In aspx,

public static string GetData(string Name, int age) {
    return "Name :" + Name + ",Age:" + age;
}

You can use the success event of ajax to populate the data.

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

Try this one

function displaySTSummaryData(x) {
    x.done(function (data) {
        $("div").html(data);
    });
}
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
kks
  • 342
  • 5
  • 25