CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2008
    Posts
    966

    [RESOLVED] Sending Data

    Hi, I am very ( I mean very ) new to J2EE and web development. I have been working with J2SE for years now and I understand Java very well.

    That being said, I have recently taken over a project that was being worked on by a co-worker who recently left the company. The project is running on Tomcat 5.5 and using Java 1.5 with AJAX, Hibernate, Struts and Tiles.

    What I am trying to fix is a section of code where there is a page with a box for comments that the user of the web site can place whatever they want into. Sometimes they would like to place a + or % symbol in the comment box.

    However, when they do so the symbols are not showing up on the other side. The reason is, they are using a POST command like a GET command and placing everything in the URL (yes all of the comment data is a key / value pair at the end of the URL).

    Now, I am no web guru, but I do know that besides having character issues (reserved chars), there is that little limitation of 1024 characters...

    Here is the code:

    Code:
    function getDataDiv(urlString )
    {
    	createRequest();
    	
    	var url =  doublecheckHost() + urlString +"&rand=" + (Math.random() * 5);
    
    	request.onreadystatechange = setDataDiv;
    	request.open("POST", url, true);
    	request.send(null); 
    	
    }
    I have tried to place a key/value pair in the request.send("key=value") field to no avail. When I go into the execute method on the other end and try to retrieve the value based off of the key I get null.

    Can somebody recommend a fix for this, or something I can read that would give me a clue? I have been pouring over AJAX web pages and have found lots of suggestions, but none have worked thus far.

    Thank you,

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Sending Data

    If I am understanding your problem correctly, you can't get certain symbols (+, %, etc.) to send properly. To fix this, you must encodeURI to encode those symbols into their url equivalents.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Feb 2008
    Posts
    966

    Re: Sending Data

    Thank you for the prompt response. I am using the encodeURL before I make my call to getDataDiv. There are two problems with this:

    1.) It works for all symbols except for the + symbol, which it considers a space. It does not place the + with %2b it thinks it is a space. Therefore, on the other end it shows up at a space and not a + symbol.

    2.) The user can only enter comments in that are less than 1024 characters.

  4. #4
    Join Date
    Feb 2008
    Posts
    966

    Re: Sending Data

    PeejAvery you're great!! encodeURI wasn't the fix, but the link you provided was lol. The encodeURIComponent was exactly what I needed.

    Thank you.

    Well, that solves one problem... Now they can add the + into their comments. However, what would you recommend I do about the 1024 limit imposed in using the URI to pass data?

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: Sending Data

    Sorry. I should have been more clear in my explanation.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Dec 2007
    Posts
    13

    Re: [RESOLVED] Sending Data

    I think that maybe the problem is caused by createRequest();

    Ajax needs the xmlhttprequest , So I think you should check this function.







    -----------------------------------------------------
    codeuu,source code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured