#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Changing form submission to ajax call


    ok i am working with wp-ecommerce and i want to change a function in my theme to be an ajax call. I am curious as to how to do that with this form.
    Code:
    <tr class='wpsc_change_country'>
               <td colspan='5'>
                  <form name='change_country' id='change_country' action='' method='post'>
                     <?php echo wpsc_shipping_country_list();?>
                     <input type='hidden' name='wpsc_update_location' value='true' />
                     <input type='submit' name='wpsc_submit_zipcode' value='Calculate' />
                  </form>
               </td>
            </tr>
    I have looked around and found some info about it. here is the link to the page for the form.
    http://docs.getshopped.org/documentation/wpsc_shipping_country_list/

    Now i am wondering if it can even be changed to an ajax call.
    So this is what i am trying to accomplish:
    1st step: onchange event-no problem, i can do that.
    2nd step: when it changes do i send the post variables via ajax to the same form? basically document.getElementById('whatever').value? Then have the ajax call the requesting page to update the post variables required for wp-ecommerce? this is where i am a little lost as you can tell.
    basically i want it to update the post variables on the wpsc-shopping_cart_page.php page without refreshing.
    Note: at the moment onchange triggers a submitform through javascript.

    Thanks for looking
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    United States
    Posts
    10
    Rep Power
    0
    Hello,

    Your form has nothing to do with it. You have to have some javascript that triggers an ajax call that collects your form data before submission to PHP.

    I think you would also have to modify the form submit script to enable the ajax behavior .

    If it's not built into wp-ecommerce you would have to hack it yourself
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0
    Originally Posted by xavier101
    Hello,

    Your form has nothing to do with it. You have to have some javascript that triggers an ajax call that collects your form data before submission to PHP.

    I think you would also have to modify the form submit script to enable the ajax behavior .

    If it's not built into wp-ecommerce you would have to hack it yourself
    That would be what the onchange event trigger would do, triggering the event. What i am wondering is about the form submit script, is it just submitting to itself? That i think is what i need to figure out.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    United States
    Posts
    10
    Rep Power
    0
    Originally Posted by Varbrad
    That would be what the onchange event trigger would do, triggering the event. What i am wondering is about the form submit script, is it just submitting to itself? That i think is what i need to figure out.
    onchange event called triggering the ajax form submit .....

    Code:
    $.ajax({  url: "formsubmitscript.php"
    you're bypassing the form action=""

    find out where the form is being submitted in the javascript
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0
    Originally Posted by xavier101
    onchange event called triggering the ajax form submit .....

    Code:
    $.ajax({  url: "formsubmitscript.php"
    you're bypassing the form action=""

    find out where the form is being submitted in the javascript
    Yup now i need to find out where the form is being submitted to and hopefully the rest will be easy.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0
    Where would this form be submitted to, wouldn't it be to itself, meaning the page it is on? if not can anyone tell me where, I have searched all over wp-ecommerce and just cant seem to find it, any help would be appreciated.

IMN logo majestic logo threadwatch logo seochat tools logo