Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional JavaScript for Web Developers 3rd edition
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers, 3rd Edition by Nicholas C Zakas; ISBN: 978-1-1180-2669-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers 3rd edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 24th, 2012, 08:07 PM
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XMLHttpRequest and POST question

Hi,

I am looking at using XMLHttpRequest with a POST request. The example on page 709 works for a form, but what if I have what I want to POST in a JavaScript string variable already?

Essentially I am looking for an elegant way to transfer a string from browser JavaScript to a LAMP server. I have done it with code that creates a form and then posts the form but that seems rather a crude approach.

(Enjoying the book by the way.)
Reply With Quote
  #2 (permalink)  
Old May 10th, 2012, 04:10 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Location: UK
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default

AFAIK all you need to do is construct a query string using names & values, pass it to send(), i.e.
Code:
xhr.send("arg1=value1&arg2=value2&arg3=value3");
that way, you're simulating how the form variables are passed to the server.
e.g.
Code:
xhr.send("user=john&email=john@smith.com");
where 'user' and 'email' take the place of form field names, and 'john' and 'john@smith.com' their respective values.

In general, to be safe, you need to call encodeURIComponent() for each arg name and value, as in the serialize() function on pages 540 - 541

HTH

Alan
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on HTTP Post dgrumbli BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 December 20th, 2006 02:03 PM
Old post from a year ago, had question plz galacticsoul General .NET 0 August 4th, 2006 12:01 PM
vbscript question (not sure where to post this) interrupt Javascript How-To 0 February 14th, 2006 10:38 AM



All times are GMT -4. The time now is 07:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.