absence of data in ajax response (or HTTP status code 206 Partial Content)

Feeling frustrated because I've wasted two hours trying to solve a simple task that I've done numerous times before. I'm not even sure where to start looking now.

Struggling to retrieve static content using ajax from local servers (Apache and Mongrel). Getting responses 200 and 206, but response text is empty (even though Content-Length header is correct). Firebug highlighting the request in red.

Javascript is generic, same results seen here: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first (just change document location to 'http://localhost:3000/whatever') So, it's probably not the issue.

Out of ideas now. Can provide http headers if needed.

Thanks!

Response Headers
Connection  close
Date    Sat, 01 May 2010 21:05:23 GMT
Last-Modified   Sun, 18 Apr 2010 19:33:26 GMT
Content-Type    text/html
Content-Length  7466

Request Headers
Host    localhost:3000
User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://www.w3schools.com/ajax/tryit_view.asp
Origin  http://www.w3schools.com

Response Headers
Date    Sat, 01 May 2010 21:54:59 GMT
Server  Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 mod_jk/1.2.28
Etag    "3d5cbdb-fb4-4819c460d4a40"
Accept-Ranges   bytes
Content-Length  4020
Cache-Control   max-age=7200, public, proxy-revalidate
Expires Sat, 01 May 2010 23:54:59 GMT
Content-Range   bytes 0-4019/4020
Keep-Alive  timeout=5, max=100
Connection  Keep-Alive
Content-Type    application/javascript

Request Headers
Host    localhost
User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Origin  null

UPDATED:
Found the issue, related to cross-domain requests. Thought restrictions were relaxed for local files and servers. (and hoped for a more descriptive error message, anyway)
Thanks everyone!

Answer №1

It appears to be a caching issue. To resolve this, clear the cache in Internet Explorer and try your experiment again. All HTTP GET requests will be stored in the cache. IE's cache also stores ajax responses. If you want to bypass this, you can add a unique parameter to the URL like '?p=blala'. Where 'p' is a parameter name and 'blala' must be unique with each request. Typically, one uses (new Date).getTime() to generate the unique 'blala'. IE will recognize the URL as new and always send a request to the server.

UPDATE: Browsers cache static data, especially if the Web server explicitly allows it: for example,

Cache-Control: max-age=7200, public, proxy-revalidate
in the server response. You can test this by visiting http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first and changing the line

xmlhttp.open("GET","ajax_info.txt",true);

to

xmlhttp.open("GET","ajax_info.txt?p=" + (new Date).getTime(),true);

then click on "Edit and Click Me >>". By clicking on the "Change Content" button, you will see the full data in the HTTP traffic. If the response includes "Accept-Ranges: bytes" and "Content-Range" like "bytes 0-4019/4020" in the HTTP header, you can learn more at

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

SDK for generating templates with JavaScript/jQuery

I am in the process of developing an SDK in JavaScript/jQuery that can generate templates based on user input, such as profile templates and dialog templates. These templates require data from an AJAX call to be created. User input should include certain ...

Guide to declaring variables using jQuery

Currently tackling a school project, I stumbled upon some online example solutions and managed to decipher most of the code. However, there is one line that has me puzzled. var $newTweet = $('<div class=tweet></div>'); My assumption ...

Creating a foolproof image polling platform: A step-by-step guide

I'm in the process of creating a webpage on my site that allows users to view a collection of images. The goal is for each registered user to choose one picture as their favorite, increasing that picture's score by one. The image with the highest ...

Prevent refreshing Google Maps when changing routes in AngularJS

Utilizing a Google map as the background for my website adds a unique visual element to the data displayed on different routes. However, I have encountered an issue where the map reloads with every route change, resulting in an unsightly flash of white tha ...

Perplexing behavior displayed by non-capturing group in JavaScript regular expressions

Here's a straightforward question for you. Regex can sometimes get tricky, so thank goodness for simplifying things... In the URL, there's a query parameter labeled ?id=0061ecp6cf0q. I want to match it and only retrieve the part after the equal ...

How to retrieve the input value in React Autosuggest

I recently began my journey into learning JavaScript and React. Currently, I am working on creating a simple table with material design. The goal is to be able to add rows to the table through a form popup and delete rows using an icon within each row. On ...

Processing requests through Axios and Express using the methods GET, POST, PUT, and DELETE

When working with express router and Axios (as well as many other frameworks/APIs), the use of GET/POST/PUT/DELETE methods is common. Why are these methods specified, and what are their differences? I understand that a GET request is used to retrieve dat ...

Vue.js - Leveraging arrays in functions for efficient iteration

I need help using a JS array in a Vue.js function for looping. Here is the code I tried: Vue: computed: { bbb: function(){ var vvv=this.Preused.length-this.quote.lines.length; let added_products=[]; if(vvv > 0){ for(var i = 0; i <= vvv-1 ...

Is there a way to determine if a directory is empty using Node.js?

Quite a while back, I submitted a question related to PHP. Now I'm facing a similar situation with Node.js where the code below appears to be sluggish when used in a loop - is there a way to achieve this using only vanilla JavaScript in pure Node.js w ...

Tips on transferring information from localstorage to a backend server using jquery

Need help sending a jsonwebtoken from localstorage using jQuery to a node server. I've attempted it this way, but it's not working. Here is the client-side code for handling requests: $(function () { // Code snippet here }); After authentic ...

Having trouble loading environment variables in NextJS on Heroku?

I am currently utilizing NextJS and deploying my application on Heroku. When the page initially loads, I am able to retrieve data through getInitialProps without any issues. However, when trying to access this data in a regular function, I encounter an er ...

After the AJAX call, the IE Browser window unexpectedly scrolls to the top of the form, rather than staying in its current position

Experiencing a PHP/JQuery/AJAX issue: I have a button positioned at the bottom of my page that triggers a JQuery function through an AJAX call. This function, based on a variable retrieved from a database using AJAX, enables a text box located at the bott ...

Information within specified dates shows all leaders

Looking to filter data based on Start Date, End Date, and HeadName. The current search query successfully filters between dates but does not properly filter the HeadName column, displaying all results instead. Sno HeadName Date Amount BillNo BillD ...

Is the value of the object in the array already present in another array of objects?

Plunker - http://plnkr.co/edit/jXdwOQR2YLnIWv8j02Yp In my angular project, I am working on a view that displays a list of users in the main container (array-A) and a sidebar with selected users (array-B). The first array (A) contains all users: [{ $$has ...

The collapsed feature of the Bootstrap 4 Navbar is not functioning as

Recently, I delved into the world of Bootstrap 4 and decided to create a collapsing menu. Everything seemed to be working fine when I clicked the button and saw the content display perfectly. However, things took a turn for the worse when I tried to collap ...

Extract form input to utilize in nodemailer

Currently I am working on a form implementation where I intend to utilize nodemailer for sending test emails to myself. My goal is to have the email inputted into the form dynamically appear in both the "to" and "subject" fields when the user submits the f ...

Show the button's value on the text box using JavaScript

When using bootstrap, I encountered an issue where the value of a button would display in a textbox upon clicking it, but then quickly disappear. This unexpected behavior left the textbox empty prematurely. <input type="submit" value="5000t "class="btn ...

The $.get method in AJAX/jQuery is functioning properly, however, there seems to be an issue with

Yesterday, I successfully made my first AJAX call by using this function that was connected to a button click event. function ajaxFunction(){ $.get("ajax/calendar.php", function(data){ $('#ajaxResponse').html(data); }); }; Now, I want t ...

Transform basic list into a two-dimensional array (grid)

Picture a scenario where we have an array: A = Array(1, 2, 3, 4, 5, 6, 7, 8, 9); We aim to transform it into a 2-dimensional array (a matrix of N x M), similar to this representation: A = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9)); It's ...

Arranging the columns of a matrix

My dilemma involves a matrix (or multidimensional array) filled with non-unique values, similar to this example: var matrix = [ [1, 3, 2, 4, 1], [2, 4, 1, 3, 2], [4, 3, 2, 1, 4] ] I am in need ...