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

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 12-21-2010, 10:07 PM   PM User | #1
hacxx
New Coder

 
Join Date: May 2010
Posts: 24
Thanks: 7
Thanked 0 Times in 0 Posts
hacxx is an unknown quantity at this point
Arrow Obtain a variable and use it

Hi,

I'm looking for some guidance for the following problem.

I want to submit a form but it requires a code that is generated by every session (not the php session type). What i'm looking for is for a piece of code that fetch the session code and set it as a variable that can be called in JS.

I know that exists in PHP the cURL that it's able to retrieve the code and set it but i don't know how to start...
hacxx is offline   Reply With Quote
Old 12-21-2010, 10:32 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
use ajax to fetch the url that contains the code.
then, search the response using regexp or dom methods.

for example, i recently moved an old-school form to an ajax form, but needed a dynamic id to prevent the submitted form from being rejected.

ajax callback snip to update hard-coded form with remote value:
Code:
 document.getElementsByName("XID")[0].value=x.responseText.match(/name="XID" value="([\w]+)"/)[1];
in that case, i was matching an input on the remote "real" page that was coded like:
Code:
<input type="hidden" name="XID" value="f2090eeb9ccccfb00714e2d377ff5a7d4127b618" />
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
hacxx (01-21-2011)
Old 01-21-2011, 12:52 PM   PM User | #3
hacxx
New Coder

 
Join Date: May 2010
Posts: 24
Thanks: 7
Thanked 0 Times in 0 Posts
hacxx is an unknown quantity at this point
Arrow

Hi,

I understand the concept of ajax but my programming skills are 0 in the matter.

Is it possible for you to provide a more complete example in how should i implement it.

Thanks for your time
hacxx is offline   Reply With Quote
Old 01-21-2011, 07:58 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
post the code you are using and i'll see if i can make it work.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 01-22-2011, 01:01 AM   PM User | #5
hacxx
New Coder

 
Join Date: May 2010
Posts: 24
Thanks: 7
Thanked 0 Times in 0 Posts
hacxx is an unknown quantity at this point
Arrow

Hi,

The site is something like the example below
http://www2.site.com/?forester

What i want is to obtain the value from the page and set it as a variable in my page
<input name="code" type="hidden" id="code" value="1b3f3988e4f45ac005f9e3951d0335f9" />

Using the snip you provided will be
document.getElementsByName("code")[0].value=x.responseText.match(/name="code" value="([\w]+)"/)[1];

If you can help me out i think i need more info about the first 2 steps you mention in your previous post

Thanks for all the help
hacxx is offline   Reply With Quote
Old 01-24-2011, 01:37 PM   PM User | #6
hacxx
New Coder

 
Join Date: May 2010
Posts: 24
Thanks: 7
Thanked 0 Times in 0 Posts
hacxx is an unknown quantity at this point
Arrow

Quote:
Hi,

If you can help me out i think i need more info about the first 2 steps you mention in your previous post
In how to make the request in ajax, obtain the html tag and retrieve to my page...
hacxx 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 06:52 AM.


Advertisement
Log in to turn off these ads.