Thread: ajax response javascript=>c#=>javascript

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

    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?

    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;
    };"GET", "ServerGateway.aspx", true);
    "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
    First I'd suggets using jQuery.ajax() – jQuery API for ajax rather than your own methods.

    To return data from an 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.

    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, 10:01 AM
  2. Replies: 2
    Last Post: 03-10-2009, 08:36 PM
  3. javascript
    By Redseal in forum Tech Board
    Replies: 8
    Last Post: 06-16-2007, 07:36 AM
  4. javascript
    By xddxogm3 in forum A Brief History of
    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