Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Alternative to Querystring in GetXmlHttpObject - large form values.

Posted on 2007-11-15
10
Medium Priority
?
1,198 Views
Last Modified: 2011-10-03
Hi
Am using ajax to save a form. A textarea field of the form is replaced by a WYSIWYG editor.

The following code seemed to work great, posting the contents of the textarea/editor to the 'ajax-content.asp' page, seamlessly updating the database using the URL variables.   Now found that if the  textarea/editor gets too long the code no longer works.  Presume this is connected to the length limit of querystrings posted via the URL .

Is there a way round this?
D
var xmlHttp
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="ajax-content.asp";
 
var MM_recordId = Form1.MM_recordId.value;
var inpContent = oEdit1.getHTMLBody();
 
url=url+"?MM_recordId="+MM_recordId;
url=url+"&inpContent="+inpContent;
 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.send(inpContent=);
}

Open in new window

0
Comment
Question by:daimo1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20288984
Since you use post, you do not have a querystring
0
 

Author Comment

by:daimo1
ID: 20289403
Probably my misunderstanding. The variables are passed via the URL, which is the issue. Is there another way to pass the variables?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20289518
I would try
1. post the actual form to a hidden frame or

2. Go get extjs or prototype.js
Then post the form using the tested ajax they use
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 20291177
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("a=1&b=2&c=3");

# where a, b and c are your variables and 1,2,3 the corresponding values (inpContent or whatever)
# don't forget to remove it from the URL
0
 

Author Comment

by:daimo1
ID: 20291834
Thanks
Tried your example and, in part, works. The length of the field isn't an issue anymore.  The only trouble is that all the spacing is lost between words, e.g 'Hello There'  turns into 'HelloThere'. when the xmlHttp is passed.
Any ideas?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 20292058
> .. spacing is lost between words
XMLHttpRequest URL-encodes the text, hence a space becomes either + or %20, if you don't get it on the server, then your server application does a wrong URL-decoding
0
 

Author Comment

by:daimo1
ID: 20297353
Maybe my issue is on the processing page 'ajax-content.asp'.

To retrieve the variable I use 'Request("inpContent")' which is getting the variable but obviously not decoding it.  Have tried 'Request.QueryString("inpContent")' but this doesn't work.  Having never used 'application/x-www-form-urlencoded' befoer how do I decode the URL?
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 2000 total points
ID: 20297678
Request.QueryString() reads the query string (GET request, manly)
I don't know anything about ASP, but there should be a Request.Post() or similar function to retrieve the posted values.

You can use a proxy or better a browser plugin like FF's LiveHttpHeader to check what the browser realy sends.

> how do I decode the URL?
convert any string of the form %HH (3 characters, where H is [0-9a-f]) to its corresponding character, %20 is a space, %78 is x ...
0
 

Author Comment

by:daimo1
ID: 20298369
Thanks for the advice on LiveHttpHeader . Gave me some insite:

Noticed that when using the original code and attaching  â€˜inpContent’ to the URL  the spaces were passed as %20, e.g. ‘Hello%20there’

When using the amended code you suggested the spaces were not changed at all. Even though I have no idea why, the processing page then ignored the spaces.

With that in mind I’ve used REPLACE to change the spaces to ‘%20’ before processing:

var inpContent = inpContent.replace(/ /g, "%20")

Not sure it’s the best way of doing things but seems to have done the trick.

Thanks for your patience and guidance.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 20299617
> .. change the spaces to ‘%20’ before processing:
.. which then sends a space as %2520 (check with LiveHttpHeader)
this identifies that your server side does a URL-decoding and probably removes spaces before you get the data in your script
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question