473,394 Members | 1,765 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,394 software developers and data experts.

ASP Page to capture AJAX XML post data

I have a script that catches javascript errors and sends them through ajax to a specified file through the POST proticol. I want to write an ASP file which can read this xml file and act on its response. I have a CGI/PERL equivalent but i'm not sure how to read the xml file in asp neatly:

use CGI;
use CGI::Carp qw(set_progname);
use XML::Simple;
my $request = CGI->new();

my $method = $request->request_method();
# method must be POST
if ($method eq 'POST') {
eval {
my $content_type = $request->content_type();
if ($content_type eq 'text/xml') {
print $request->header(-status =>
'415 Unsupported Media Type', -type => 'text/xml');
croak "Invalid content type: $content_type\n";
}
# when method is POST and the content type is neither
# URI encoded nor multipart form, the entire post
# is stuffed into one param: POSTDATA
my $error_xml = $request->param('POSTDATA');
my $ref = XML::Simple::XMLin($error_xml);
my ($name, $msg, $location) =
($ref->{'name'}, $ref->{'message'}, '');
$location = $ref->{'location'} if (defined($ref->{'location'}));
# this will change the name of the carper in the log
set_progname('Client-side error');
my $remote_host = $request->remote_host();
carp "name: [$name], msg: [$msg], location: [$location]";
};
if ($@) {
print $request->header(-status => '500 Internal server error',
-type => 'text/xml');
croak "Error while logging: $@";
} else {
# this response code indicates that the operation was a
# success, but the client should not expect any content
print $request->header(-status => '204 No content',
-type => 'text/xml');
}
} else {
print $request->header(-status => '405 Method not supported',
-type => 'text/xml');
croak "Unsupported method: $method";
}
Oct 31 '06 #1
4 4583
nedu
65
Hi,

Send the xml file which u have got. I will give you the asp code . .
Nov 2 '06 #2
Hi,

Send the xml file which u have got. I will give you the asp code . .

Sure - I can send my ajax code if you contact me. The bulk of it can be found here:

http://www.xml.com/pub/a/2005/05/11/ajax-error.html

with slight modifications the returned xml looks like the following:

<?xml version=1.0"?>
<error>
<name>TypeError</name>
<message>Object expected</message>
<location>http://www.somasdhkhsdaf.com, function:foo()</location></error>

the important bit of this code is that the javascript ajax reads the state change of the asp page to state 204 and realises it has been successful.

I can provide you with any extra information you need

Thanks

Rich
Nov 5 '06 #3
nedu
65
<%
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
Set objLst = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.Load (Server.MapPath("filename.xml"))
If objXML.parseError.errorCode <> 0 Then
handle the error
End If

Set objLst = objXML.getElementsByTagName("*")

For i = 0 to (objLst.length – 1)

If objLst.item(i).nodeName = "error" Then
StrERR = objLst.item(i).text
Handle the Error here . . .

'Exit For
End If

Next
%>


Does thisa code help u . . . If u have any doubts mail me at mneduu@gmail.com . .

Thanks & regards

(M. Nedu . .)
Nov 6 '06 #4
Hi,

That isn’t quite the problem. First the asp page isn’t reading the xml file form the server – it has to get it from the request of the page. Second it is the return of the page which is causing issues. I can capture the xml crudely using the following:

<%@LANGUAGE="VBSCRIPT"%>
<%
Response.ContentType = "text/xml"

set oXML = Server.CreateObject("Msxml2.DOMDocument")
oXML.setProperty "ServerHTTPRequest", True
oXML.async = False
oXML.load(Request)
Response.Status = "204 No Content"

Response.End


%>

But that doesn’t feedback successful to the ajax correctly

Thanks
Rich Halliwell
Nov 6 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jake Barnes | last post by:
I'm trying to learn AJAX so tonight I sat down and came up with a little toy that I can do tests with. You can see it here: http://www.publicdomainsoftware.org/ajaxExperiment.htm I've got...
4
by: Tim | last post by:
Hello, I have a web page that a user enters in information and selects some products. On submit the page the info is saved to a db, connects to third party web apps and retrieves data, and...
14
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So,...
3
by: radix | last post by:
Hello, I have a aspx page with ajax scriptmanger update panel etc. I also have public string variables on the aspx page. Whenever postback happens from Ajax update panel, at server side all...
2
by: ravisuguna | last post by:
Hi, I have a php page which has some checkboxes ,textfields and values.If I select a checkbox ,a particular value will be displayed in a textfield.I have a "go"button in the same page.I want the...
2
by: JM_newsgroups | last post by:
Hi, When I do a postback on a particular AJAX-enabled page, I get a popup that says: "Sys.WebForms.PageRequestManagerParserErrorException: The message received could not be parsed. . . . " It...
2
by: Max | last post by:
I recently moved to ASPnet Ext 3.5 What I can't get with Ajax and History browser managemet is this: User fills some fields (dropdown and textbox) on page 1 (all are in an update panel) User...
5
by: vasilis | last post by:
I have a list box in a site with which I capture a selected value with the onChange event using the capture_value() function (code listed below). This function passes 2 arguments, i.e., 'str' which...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.