-
Feb 3rd, 2012, 01:21 PM
#1
Thread Starter
Member
[RESOLVED] AJAX request call not working
Hello,
I'm trying to track down a bug.
On the client side, I've got some javascript code that makes an AJAX request to the server. The request seems to be returning to the callback function with readystate 4 but no XML data. I'm working in Visual Studios 2008 and I have confirmed with the debugger that the codebehind C# code that's supposed to be run when the server receives the AJAX request isn't running at all (which explains the lack of XML data in the response). I'm having trouble figuring out why this is.
The AJAX call looks like this:
Code:
http_request.open(method, filename, async);
http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http_request.send(data);
method = 'POST'
filename = 'ChargeCodeSave.aspx'
async = true
data is a big long string that's too big to post.
Once this request gets sent, it goes off into cyber-space and the debugger can't trace it. All I know is that the codebehind specified in ChargeCodeSave.aspx, which is ChargeCodeSave.aspx.cs as the following (and only) line from ChargeCodeSave.aspx shows:
<%@ Page language="c#" Codebehind="ChargeCodeSave.aspx.cs" AutoEventWireup="True" Inherits="CoreData.Net2.ChargeCodeSave" %>
isn't run.
I don't think you'd need to know what the Page_Load method in the C# codebehind file looks like (since it's not even executing), but here it is anyway:
Code:
protected void Page_Load(object sender, System.EventArgs e)
{
// Clean the cache of CommonSession for each page load.
TimeSheetUtility.ResetSessionCache();
MessageBox.Show("message box");
XmlDocument xmlReply = null;
ParseInput ();
// Parse the input variables
switch (Request.Form["action"])
{
case "validate" :
xmlReply = Validate ();
break;
case "process" :
xmlReply = Process ();
break;
default :
break;
}
// Set the encoding of the document
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/xml";
// Output the response of the loading
Response.Write (xmlReply.OuterXml);
}
Can anybody suggest what the problem might be?
-
Feb 3rd, 2012, 02:14 PM
#2
Thread Starter
Member
Re: AJAX request call not working
UPDATE: it doesn't seem to like "x-www-form-urlencoded". If I replace that with "x-www-form-utf8encoded", as in the following line:
http_request.setRequestHeader("Content-Type", "application/x-www-form-utf8encoded");
the codebehind actuall executes.
The problem now is that the request form is empty so that Request.Form["action"] doesn't give me anything.
I'm also not sure that "application/x-www-form-utf8encoded" exists. Is there something else I can use?
-
Feb 5th, 2012, 12:07 AM
#3
Re: AJAX request call not working
application/x-www-form-urlencoded describes a set of name/value pairs.
data should look like this:
Code:
field1=value1&field2=value2&field3=value3
etc.
If you are looking for Request.Form["action"], then there must be a field named action in the data string.
-
Feb 6th, 2012, 10:12 AM
#4
Thread Starter
Member
Re: AJAX request call not working
Thanks Penagate
We think we've found the problem though we haven't tested it yet via an implementation. We believe the data string is too long and that it's cutting off somewhere in the middle. We're going to split it up into segments and see if that helps.
-
Feb 6th, 2012, 11:07 AM
#5
Re: AJAX request call not working
well a url encoded (which implies a GET rather than a POST) does have a limit... POST on the other hand should allow for a rather significant larger amount of data. That said, I'm thinking that the reason it failed before was because you're sending it via POST, but then encoding the data into a URL Encoded string... which I think makes the POSTed form then basically empty (thus the lack of action on the back end.) Once you changed it, it allowed the POST to actually happen... so now you're making progress.
The next step I think (at least if it were me) would be to break it down... chunk it down into a couple of smaller pieces, maybe just a couple of fields... then rather then looking for something specific (like the action field) ... simply have it spit back what it does receive... that should tell you real quick if the size of the data stream is the problem, or the data stream itself is improperly formed, or something else is interfering with it.
-tg
-
Feb 6th, 2012, 11:16 AM
#6
Re: AJAX request call not working
Do you have a callback function in the JS that gets run when the ajax completes?
It should give you a meaningful message as to what happened.
-
Feb 6th, 2012, 09:15 PM
#7
Thread Starter
Member
Re: AJAX request call not working
Splitting up the string worked.
The callback function was receiving an empty XML document. Now it is not empty.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|