Page 1 of 1

jQuery's Form plugin

Posted: Mon Mar 12, 2007 1:31 pm
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>

Posted: Mon Mar 12, 2007 1:40 pm
by feyd
....onsubmit() ?

Posted: Mon Mar 12, 2007 2:08 pm
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 :(

Posted: Mon Mar 12, 2007 2:10 pm
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? :?

Posted: Mon Mar 12, 2007 2:19 pm
by nickvd
Nope... Security reasons.

The only way is by a server side proxy.

Posted: Mon Mar 12, 2007 5:01 pm
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);
 

Posted: Mon Mar 12, 2007 5:05 pm
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

Posted: Mon Mar 12, 2007 11:20 pm
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?

Posted: Tue Mar 13, 2007 1:47 am
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.

Posted: Tue Mar 13, 2007 1:17 pm
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!

Posted: Tue Mar 13, 2007 11:03 pm
by feyd
Ah, the remnants of archaic techniques for creating "my own" language.. :roll:

Posted: Wed Mar 14, 2007 1:20 am
by Kieran Huggins
I see you're looking for another cart system ;-)

Probably best in this case.