ajax response javascript=>c#=>javascript

This is a discussion on ajax response javascript=>c#=>javascript within the C# Programming forums, part of the General Programming Boards category; I created the following code in a javascript file. On the ServerGateway.aspx page load, I do some logic, and want ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    ajax response javascript=>c#=>javascript

    I created the following code in a javascript file.
    On the ServerGateway.aspx page load, I do some logic, and want to return that data to the calling javascript.
    I have searched online, but fail to find logic to return the data.
    Does anyone have any idea how to do this?

    Code:
    function ajaxToCSharp() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    document.getElementById("centerStage").innerHTML = xmlhttp.responseText;
    }
    };
    xmlhttp.open("GET", "ServerGateway.aspx", true);
    xmlhttp.send();
    }
    
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    First I'd suggets using jQuery.ajax() – jQuery API for ajax rather than your own methods.

    To return data from an asp.net page simply use Response.Write ( HttpResponse.Write Method (String) (System.Web) ) to write it out.
    Make sure you remove all markup except the <%@ Page> tag from the aspx file or it will be merged with your result.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some Javascript help
    By Elysia in forum Tech Board
    Replies: 2
    Last Post: 07-30-2010, 11:01 AM
  2. Replies: 2
    Last Post: 03-10-2009, 09:36 PM
  3. javascript
    By Redseal in forum Tech Board
    Replies: 8
    Last Post: 06-16-2007, 08:36 AM
  4. javascript
    By xddxogm3 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-07-2003, 10:50 AM
  5. javascript
    By bluehead in forum Game Programming
    Replies: 4
    Last Post: 12-04-2001, 09:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21