473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

AJAX and ashx handlers

I am doing an AJAX call using JQuery on my page to [WebMethod] which returns
JSON objects and everything works fine.
Now I decided to use ashx handler instead of [WebMethod] and simply write
JSON out. Then my problems begun.

So here is JQuery call

$.ajax({
type: 'POST',
url: url,
data: '{id:5}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(result) { ...},
error: function() {... }
});

If url = "Default.aspx/Remove" wich is WebMethod it works perfectly
If url = "ServiceCalls.ashx/Fetch" then the call fails with an error 12030
which is comes from IE's XMLHttpRequest object and stand for
"The connection with the server has been reset or terminated"
Here are strange things.
1. It works in FireFox. Only IE has a problem
2. If i try to debug application it works.
3. If i have a Fiddler running it works.

I tried to analyze with Fiddler 2 requests (and replies) to
"Default.aspx/Remove" and to "ServiceCalls.ashx/Fetch" and they look
absolutely identical.

I rulled out that i output incorrect JSON since it works with Fiddler in IE
and with FireFox.

So I am completely puzzled. What does [WebMethod] does differently?

Thanks
George.

Nov 14 '08 #1
3 17638
Finally figured it out....

The difference between [WebMethod] and my .ashx hanler is that [WebMethod]
reads the input stream completelly and my .ashx handler did not.

That made IE's XMLHttpRequest object to fail properly get the response. Not
sure why is it being such a "girl". Cause FireFox does not have a problem.

Also it explains why it worked with Fiddler. The Fiddler were reading the
input stream So here is the code the handler must have if you using it in
AJAX call

System.IO.Stream st = context.Request.InputStream;
byte []buf = new byte[100];
while (true)
{
int iRead = st.Read(buf, 0, 100);
if( iRead == 0 )
break;
}
st.Close();

So always read the the InputStream completely even if you are not interested
in it...
George.

"George" <no*****@comcast.netwrote in message
news:uU**************@TK2MSFTNGP02.phx.gbl...
>I am doing an AJAX call using JQuery on my page to [WebMethod] which
returns JSON objects and everything works fine.
Now I decided to use ashx handler instead of [WebMethod] and simply write
JSON out. Then my problems begun.

So here is JQuery call

$.ajax({
type: 'POST',
url: url,
data: '{id:5}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(result) { ...},
error: function() {... }
});

If url = "Default.aspx/Remove" wich is WebMethod it works perfectly
If url = "ServiceCalls.ashx/Fetch" then the call fails with an error 12030
which is comes from IE's XMLHttpRequest object and stand for
"The connection with the server has been reset or terminated"
Here are strange things.
1. It works in FireFox. Only IE has a problem
2. If i try to debug application it works.
3. If i have a Fiddler running it works.

I tried to analyze with Fiddler 2 requests (and replies) to
"Default.aspx/Remove" and to "ServiceCalls.ashx/Fetch" and they look
absolutely identical.

I rulled out that i output incorrect JSON since it works with Fiddler in
IE and with FireFox.

So I am completely puzzled. What does [WebMethod] does differently?

Thanks
George.
Nov 14 '08 #2
ajax libraries hosted in IE use ActiveXObject("Msxml2.XMLHTTP"), which is
part of the msxml com library. it has been available for years (IE 5.0).

for all other browsers the ajax libraries use the browser builtin object
XMLHttpRequest. the w3c has defined how this object works (optimized for
javascript). its close but not same as the ms com object.

-- bruce (sqlwork.com)
"George" wrote:
Finally figured it out....

The difference between [WebMethod] and my .ashx hanler is that [WebMethod]
reads the input stream completelly and my .ashx handler did not.

That made IE's XMLHttpRequest object to fail properly get the response. Not
sure why is it being such a "girl". Cause FireFox does not have a problem.

Also it explains why it worked with Fiddler. The Fiddler were reading the
input stream So here is the code the handler must have if you using it in
AJAX call

System.IO.Stream st = context.Request.InputStream;
byte []buf = new byte[100];
while (true)
{
int iRead = st.Read(buf, 0, 100);
if( iRead == 0 )
break;
}
st.Close();

So always read the the InputStream completely even if you are not interested
in it...
George.

"George" <no*****@comcast.netwrote in message
news:uU**************@TK2MSFTNGP02.phx.gbl...
I am doing an AJAX call using JQuery on my page to [WebMethod] which
returns JSON objects and everything works fine.
Now I decided to use ashx handler instead of [WebMethod] and simply write
JSON out. Then my problems begun.

So here is JQuery call

$.ajax({
type: 'POST',
url: url,
data: '{id:5}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(result) { ...},
error: function() {... }
});

If url = "Default.aspx/Remove" wich is WebMethod it works perfectly
If url = "ServiceCalls.ashx/Fetch" then the call fails with an error 12030
which is comes from IE's XMLHttpRequest object and stand for
"The connection with the server has been reset or terminated"
Here are strange things.
1. It works in FireFox. Only IE has a problem
2. If i try to debug application it works.
3. If i have a Fiddler running it works.

I tried to analyze with Fiddler 2 requests (and replies) to
"Default.aspx/Remove" and to "ServiceCalls.ashx/Fetch" and they look
absolutely identical.

I rulled out that i output incorrect JSON since it works with Fiddler in
IE and with FireFox.

So I am completely puzzled. What does [WebMethod] does differently?

Thanks
George.

Nov 14 '08 #3
Starting from IE 7 there is builtin XMLHttpRequest object (in IE)
http://msdn.microsoft.com/en-us/libr...74(VS.85).aspx

Nevertheless my post was not about that....
George.

"bruce barker" <br*********@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
ajax libraries hosted in IE use ActiveXObject("Msxml2.XMLHTTP"), which is
part of the msxml com library. it has been available for years (IE 5.0).

for all other browsers the ajax libraries use the browser builtin object
XMLHttpRequest. the w3c has defined how this object works (optimized for
javascript). its close but not same as the ms com object.

-- bruce (sqlwork.com)
"George" wrote:
>Finally figured it out....

The difference between [WebMethod] and my .ashx hanler is that
[WebMethod]
reads the input stream completelly and my .ashx handler did not.

That made IE's XMLHttpRequest object to fail properly get the response.
Not
sure why is it being such a "girl". Cause FireFox does not have a
problem.

Also it explains why it worked with Fiddler. The Fiddler were reading the
input stream So here is the code the handler must have if you using it in
AJAX call

System.IO.Stream st = context.Request.InputStream;
byte []buf = new byte[100];
while (true)
{
int iRead = st.Read(buf, 0, 100);
if( iRead == 0 )
break;
}
st.Close();

So always read the the InputStream completely even if you are not
interested
in it...
George.

"George" <no*****@comcast.netwrote in message
news:uU**************@TK2MSFTNGP02.phx.gbl...
>I am doing an AJAX call using JQuery on my page to [WebMethod] which
returns JSON objects and everything works fine.
Now I decided to use ashx handler instead of [WebMethod] and simply
write
JSON out. Then my problems begun.

So here is JQuery call

$.ajax({
type: 'POST',
url: url,
data: '{id:5}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(result) { ...},
error: function() {... }
});

If url = "Default.aspx/Remove" wich is WebMethod it works perfectly
If url = "ServiceCalls.ashx/Fetch" then the call fails with an error
12030
which is comes from IE's XMLHttpRequest object and stand for
"The connection with the server has been reset or terminated"
Here are strange things.
1. It works in FireFox. Only IE has a problem
2. If i try to debug application it works.
3. If i have a Fiddler running it works.

I tried to analyze with Fiddler 2 requests (and replies) to
"Default.aspx/Remove" and to "ServiceCalls.ashx/Fetch" and they look
absolutely identical.

I rulled out that i output incorrect JSON since it works with Fiddler
in
IE and with FireFox.

So I am completely puzzled. What does [WebMethod] does differently?

Thanks
George.

Nov 15 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Detlef Hüttenbach | last post by:
There is a bug within the Handler factory that messes up the streams loaded from memory. Workaround: Don't use the HandlerFactory, i.e.: ashx-handlers when you need to print images from streams...
2
by: Roshawn Dawson | last post by:
Hi, While browsing the web, I came across a file extension in ASP.NET called ..ashx. Does anyone know what this file type is for? Is it useful? How do you use it? Thanks, Roshawn
5
by: Roshawn Dawson | last post by:
Hi, Has anybody created an entire asp.net app using only ashx files? I know that they are simply handlers used by the asp.net worker process. I hear that they are in some respects better than...
3
by: Erik Cruz | last post by:
Hi. I will start to migrate an asp.net 1.1 application to 2.0. This application uses an Iframe that simply calls a method to update a field on my databse every minute. In order to do this, I...
3
by: Alok yadav | last post by:
I have an open IP and on that IP our main application is hosted. it uses ajax. in web.config file i have register ajax handlers. there are also other sites or project on that IP. now my problem is...
9
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post by:
Hi all, I followed first walk through sample from http://ajax.asp.net/docs/tutorials/IntroductionUpdatePanel.aspx to create my first testing page, The problem is after I clicked that botton, it...
0
by: nickmarkham | last post by:
Hi, I have 'localized' the button images in my web app by using an HTTP handler file for each image so the correct langauge imagebutton can be loaded depending on the users language. In the...
1
by: =?Utf-8?B?Z2hhdXNl?= | last post by:
I'm trying to stream in image from another domain asynchronously. My ashx looks like this: <%@ WebHandler Language="VB" Class="Handlers.AsyncImageHandler" Debug="true" %> Here is the vb:...
1
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.