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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:15:17+00:00 2026-06-17T07:15:17+00:00

I am trying to test using the JavaScript XMLHttpRequest() object in an ASP.NET MVC

  • 0

I am trying to test using the JavaScript XMLHttpRequest() object in an ASP.NET MVC application.
I have written the following test code which I put into a View –

<script type="text/javascript">
var request;

function getAJAX() {
    request = new XMLHttpRequest();
    request.open("GET", "test.txt");
    request.onreadystatechange = checkData();
    request.send(null);
}


function checkData() {
    if (request.readyState == 4) { 
        if (request.status == 200) { 
            alert(request.responseText);                
        }
    }
}
</script>

<form action="">
    <p>
        <button type="button" onclick="getAJAX()">DO IT!</button>
    </p>
</form> 

When I click in the “DO IT!” button, the script functions get called, but the "request.onreadystatechange" never changes.
I have a few questions about this –

  1. Is there a simple way to trace what is happening with the request.open() call?
  2. Will the XMLHttpRequest() object even work in an ASP.NET MVC application?
  3. Will I have to make changes to the Global.asax file (or other changes) to make this work?
  4. I have "test.txt" in the "base" directory (the same location as the Global.asax file) is that where the request.open call will look?

(NOTE: I am trying to do this without jQuery)

Thanks very much!

  • 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-17T07:15:19+00:00Added an answer on June 17, 2026 at 7:15 am

    You’re setting the callback to onreadystatechange to the result of executing checkData. Set onreadystatechange equal to checkData instead and you should be good to go:

    function getAJAX() {
        request = new XMLHttpRequest();
        request.open("GET", "test.txt");
        request.onreadystatechange = checkData; // Don't execute checkData
        request.send(null);
    }
    

    As for your other questions:

    Is there a simple way to trace what is happening with the request.open() call?

    Use Firebug or the development tool of your choice to inspect AJAX requests.

    Will the XMLHttpRequest() object even work in an ASP.NET MVC application?

    Yes, it’ll work fine.

    Will I have to make changes to the Global.asax file (or other changes) to make this work?

    Not that I’m aware of.

    I have “test.txt” in the “base” directory (the same location as the Global.asax file) is that where the request.open call will look?

    Maybe? It really depends on your routing rules and how you have IIS configured.

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

Sidebar

Related Questions

I have an HTML/JavaScript app that I'm trying to convert to an App using
I have a simple HTML page (ratings.html) that I'm trying to test using HtmlUnit.
I'm trying to create a simple AJAX & web service test (using C# .Net
Using Javascript I'm trying to test whether or not a DIV with the id
I'm trying to test a chat application and I have been facing a specific
I am trying to integrate iScroll in my application using javascript-jquery.mobile.iscroll plugin . I
I am using the javascript test-runner Mocha. I have a test that is failing,
I'm trying to test using SFML's full screen mode, however it crashes every time
I'm trying to test using QTP a web app that is using ajax4jsf to
I am trying to test a sinatra app using minitest and capybara but get

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.