[RESOLVED] AJAX request call not working-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] AJAX request call not working

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    Resolved [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?

  2. #2

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    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?

  3. #3
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    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.

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    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.

  5. #5
    PowerPoster
    Join Date
    May 2002
    Posts
    24,106

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    15,556

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.