Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-31-2007, 04:04 AM   PM User | #1
teracomp
New to the CF scene

 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
teracomp is an unknown quantity at this point
Sending Large amounts of text via AJAX/PHP

Background:
I have a page that list hundreds of records for a user to browse for editing. When editing a <div> is toggled that allows easy editing (the div is actually just set with display:none on the page).
When the user is done, they click Save to hide the div and send the edited data to a MySql database without refreshing the page via AJAX/PHP.
All of AJAX/PHP code is working...works fine as long as the text is small.

Problem:
The text to be edited can be quite large (as much as 5,000 characters), so using a GET parameter is problematic.

Question:
Is it possible to use AJAX/PHP to grab the data from the page? Or is this just a bad design on my part?
teracomp is offline   Reply With Quote
Old 03-31-2007, 04:38 AM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
It's entirely possible to use HTTP POST for this kind of situation. One thing to consider though, is that you should avoid sending too much information from the client to the server. It's not uncommon, especially for DSL connections but also for fiber and copper, that connections are assymetric. My parents have a 5 Mbit downstream connection but just 250 kbit upstream connection, for example.

One example is an AJAX site for collaboratively editing SVG that I helped with the scripting for. We found that some users (me among them) had strangely bad transmit rates even though they were sitting on very fast connections. The reason turned out to be that we were actually gated on upload speed and not download speed because we sent very much information both directions.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 03-31-2007, 05:14 AM   PM User | #3
teracomp
New to the CF scene

 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
teracomp is an unknown quantity at this point
That's encouraging. I don't think we'll have a problem with data xfer since it's all text/html, but will watch that.

I'm glad POST will work, but I don't know how to retrieve the $_POST var on the php script that the JavaScript request is calling.

I'm using the prototype library, so here's my call:

var url = 'saveActionItem.php?divID='+id+'&key='+myKey+'&itm='+myItm;
var myAjax = new Ajax.Request(
url, { method: 'post',
onComplete: update_page
});

The $_GET params are designed to control my sql query.

On the php side, I grab the text using:
$actTxt = $_POST['validFormVar'];

However, the $_POST var is not set, so $actTxt="" and my update essentially deletes the text.

Can you point me in the right direction?
teracomp is offline   Reply With Quote
Old 04-03-2007, 07:02 PM   PM User | #4
iLLin
Regular Coder

 
Join Date: Oct 2005
Location: Right Here
Posts: 654
Thanks: 1
Thanked 0 Times in 0 Posts
iLLin is an unknown quantity at this point
I think the function is stringtoQuery or something. I will find out and edit. Once sec.

EDIT: query = formID.toQueryString()

Then put in your call... "postbody: query"

Thats the function you need to post the information.

Last edited by iLLin; 04-03-2007 at 07:04 PM..
iLLin is offline   Reply With Quote
Old 04-06-2007, 09:05 AM   PM User | #5
teracomp
New to the CF scene

 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
teracomp is an unknown quantity at this point
Thanks for the post, but I'm still fighting this issue.

formID.toQueryString() produces the error: myFrm.toQueryString() is not a function

in this case, i create a reference to the form using:
var myFrm = document.getElementById('frm'+myKey+myItm);
// alert(myFrm.length);
var query = myFrm.toQueryString();

(the alert was here to check that I got the form)

It looks like toQueryString is designed to create a query string from a hash. Seems like that would still end up hitting the 2048-char query string limit and my text often contains an average of 2428 characters with a current max of 14,604 characters
teracomp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:09 AM.


Advertisement
Log in to turn off these ads.