cannot load dynamically generated xml using XMLHttpRequest on google chrome

Go To StackoverFlow.com

0

I have a aspx file that generates XML output. On another page I am trying to use XMLHttpRequest open method to read the XML outputted from the aspx file. FF, IE, Safari all seem to work except Chrome. However on chrome if I directly go to the aspx page on the address bar xml is generated as expected. Any help is appreciated.

Here is the aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProviderFinderXML.aspx.cs" Inherits="Pages_ProviderFinderXML" %>

<%@ OutputCache Duration="6" VaryByParam="Type" %>

Aspx code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Xml;
using System.ServiceModel.Syndication;
using System.Text;
using System.Data;

public partial class Pages_ProviderFinderXML : System.Web.UI.Page
{    
    protected string appPath = Helper.GetApplicationPath();
    private DataTable dataTable, dataTable2;
    private Helper helper = new Helper();

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected override void OnInit(EventArgs e)
    {
        float center_lat = 0, center_lng = 0;
        int radius = 0;
        if (Request.QueryString["lat"] != null)
            center_lat = Common.ConvertToFloat(Request.QueryString["lat"].ToString());
        if (Request.QueryString["lng"] != null)
            center_lng = Common.ConvertToFloat(Request.QueryString["lng"].ToString());
        if (Request.QueryString["radius"] != null)
            radius = Common.ConvertToInt(Request.QueryString["radius"].ToString());
        int categoryId = 0;
        if (Request.QueryString["categoryId"] != null)
            categoryId = Common.ConvertToInt(Request.QueryString["categoryId"].ToString());

        Response.Buffer = false;
        Response.Clear();
        Response.ContentType = "application/xml";
        XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
        xmlWriter.WriteStartDocument();

        xmlWriter.WriteStartElement("markers");

        int perPage = 0, currentPage = 1;

        dataTable = helper.DIR_GetNearbyDirectoryMembersByLatLng(center_lat, center_lng, radius, categoryId, perPage, currentPage);

        if (dataTable.Select().Length > 0)
        {
            xmlWriter.WriteAttributeString("title", cRow["title"].ToString().Replace("'", "\\'"));
        }
        xmlWriter.WriteEndDocument();

        xmlWriter.Flush();

        xmlWriter.Close();

        base.OnInit(e);

        Response.Close();
    }


    private string GetFullyQualifiedUrl(string url)
    {
        return string.Concat(Request.Url.GetLeftPart(UriPartial.Authority), ResolveUrl(url));
    }

}

Here is the test page code part that makes the call to that aspx page:

<script type="text/javascript">

            $(document).ready(function () {
                searchLocationsNear();
            });

            function searchLocationsNear() {
                var searchUrl = 'http://localhost/integrativediagnosis2/Pages/ProviderFinderXML.aspx?lat=42.3584308&lng=-71.0597732&radius=20';
                var xmlhttp;
                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.open("GET", "ProviderFinderXML.aspx?lat=42.3584308&lng=-71.0597732&radius=20", false);
                xmlhttp.send();
            }

        </script>
2012-04-05 18:00
by user1255409
The problem is on the code that generates the XML. Apparently if we have Response.Close(); Chrome doesnt behave. If we get rid of it works fine. SO THE SOLUTION WAS GETTING RID OF Response.Close() - user1255409 2012-04-05 18:57


1

Use JQuery.ajax instead handmade calls.

Use Fiddler or other HTTP tracing tool to confirm that all requests are send/received as you expect.

I don't see anything immediately wrong. There is no code tha read output, so it is not clear what "does not work in Chrome" mean.

2012-04-05 18:14
by Alexei Levenkov
The problem is on the code that generates the XML - user1255409 2012-04-05 18:55
Now I see what the problem is - you are closing underlying stream (Response.Close) before finishing writes to that stream. So if you move that call in correct place (or remove it as you've did) it will work. For future questions consider at least stating what the problem is.. - Alexei Levenkov 2012-04-05 19:57
Alexei - even if we close at the end it doesnt work with chrome. Looks like it works on all browsers if we take that line off - user1255409 2012-04-20 21:05
Ads