Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    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...

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    hacxx (01-21-2011)

  • #3
    New Coder
    Join Date
    May 2010
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    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

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    post the code you are using and i'll see if i can make it work.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    New Coder
    Join Date
    May 2010
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    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

  • #6
    New Coder
    Join Date
    May 2010
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Arrow

    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...


  •  

    Posting Permissions

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