jQuery's Form plugin

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

jQuery's Form plugin

Post by Luke »

I'm using jQuery's form plugin to unobtrusively convert regular forms to ajax forms. Worked well for a while, but I started working on it today, and messed something up somehow. For some reason now when it submits the form, the response text from the page the form is submitting to with ajax is being shown to the user (they are being redirected to that page) instead of being then processed by the callback function. Does anybody know why this might be happening?

Code: Select all

      $("#productform").submit(function(){
          var options = {
              beforeSubmit:  prepareData,
              success:       updatePage,
              dataType:      'json'
          };
          $(this).ajaxSubmit(options);
          return false;
      });

Code: Select all

             <form id="productform" name="productform" method="post" action="http://www.example.com/php/add_product.php">
             <input type="hidden" name="Action" value="ADPR">
             <input type="hidden" name="Screen" value="PROD">
             <input type="hidden" name="Store_Code" value="&mvte:store:code;">
             <input type="hidden" name="Session_ID" value="&mvt:global:session_id;">
             <input type="hidden" name="Product_Code" value="&mvte:product:code;">
             <input type="hidden" name="Category_Code" value="&mvt:global:category_code;">
             <div class="valign_middle">Quantity: <input type="text" name="Quantity" class="text" value="1" size="1"> <input type="image" src="images/buttons/add_to_cart.gif" alt="Add to cart" class="valign_middle" /></div>
             <div id="product_attributes"><mvt:item name="product_attributes" param="product:id" /></div>
             </form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

....onsubmit() ?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

stupid question, but are you sure you have javascript turned on?

I've forgotten that I turned it off, and it took over an hour before I realized it :(
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

yea javascript is turned on, and it is submit() not onsubmit() (jquery). The reason it wasn't working is because I changed where it was submitting to to a remote url, which I guess is not allowed. The server that this page is running on does not have PHP installed. Are there any tricks to allow javascript to call a remote url? :?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Nope... Security reasons.

The only way is by a server side proxy.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

I think Feyd correct. What's up with the submit().

Code: Select all

var options = {
  beforeSubmit:  prepareData,
  success:       updatePage,
  dataType:      'json'
};
$("#productform").ajaxForm(options);
 
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I'm attaching ajaxSubmit to my form's submit event. That's what it says to do here:
http://www.malsup.com/jquery/form/#api
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

the .submit() is a jQuery function that either fires the submit event (if it's empty) or attaches an event handler if it's given a function as an argument - NSG has it 100% correct. In fact, it was only the "same origin" security policy that was getting in his way.

http://taossa.com/index.php/2007/02/08/ ... in-policy/

You're not trying to submit to your own domain?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

the domain it's on is store.example.com (no PHP) and the place it needs to post to is http://www.example.com (has PHP). store.example.com does have mivascript installed, but I still haven't had the time or motivation to dig into that heap ( Image ). I already talked to the hosting company, and they said they will not install any other software on their ecommerce machines. I'm getting pretty sick of my host and of miva... I really am.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

So here's my Miva Script... just thought I'd show you guys just how magnificent this language is:

Code: Select all

<MvASSIGN NAME="g.active" VALUE="0">
<MvASSIGN NAME="g.contentheader" VALUE="{ miva_output_header('Content-Type','application/json; charset=UTF-8') }">

<MvIF EXPR="{NOT ISNULL g.Product_Attributes[1]}">
    <MvASSIGN NAME="g.Product_Code" VALUE="{g.Product_Attributes[1]}">
</MvIF>

<MvIF EXPR="NOT ISNULL g.Product_Code">

    <MvASSIGN NAME="g.db" VALUE="test@test">
    <MvASSIGN NAME="g.user" VALUE="test">
    <MvASSIGN NAME="g.pass" VALUE="test">

    <MvOPEN NAME="verify" DATABASE="{g.db}" USER="{ g.user }" PASSWORD="{ g.pass }" type="MySQL">
    <MvOPENVIEW NAME="verify" VIEW="products" QUERY="SELECT active FROM s01_Products WHERE `code` = ? LIMIT 1;" Fields="g.Product_Code">

         <MvASSIGN NAME="g.active" VALUE="{ products.d.active }">

    <MvCLOSEVIEW NAME="verify" VIEW="products">
    <MvCLOSE NAME="verify">
    
    <MvIF EXPR="{ g.active NE '1' }">    
        {"status":"error","error":"Product not available"}
    <MvELSE>
        {"status":"success","code":"<MvEVAL EXPR="{g.Product_Code}">"}
    </MvIF>
    
<MvELSE>
    {"status":"error","error":"No product code"}
    <MvEXIT>
</MvIF>
Nice and readable, huh? Bleh!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Ah, the remnants of archaic techniques for creating "my own" language.. :roll:
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I see you're looking for another cart system ;-)

Probably best in this case.
Post Reply