Jump to content

Hi i need a ajax equivelant to this Jquery posting.


antonyfal

Recommended Posts

Hello.

I have this code which works on a page on its own, But on my site it does not work. The Jquery does not load and i have also tried Prototype. It too conflicts..

here is my function, when the button is presssed the following is supposed to happen, but i have problems with the jquery. YES! i have tried the noConflict..

Here is my code:

 

me.emailCheckout = function() {

    var div = me.updateCartView( document.createElement("diver") );

    diver = "<div class='storeCart_items'>" + div.innerHTML + "</div>";

    var buyersalute = jQuery("#buyersalute").val();

    var buyerfirstname = jQuery("#buyerfirstname").val();

    var buyerlastname = jQuery("#buyerlastname").val();

    var buyerstreet = jQuery("#buyerstreet").val();

    var buyertown = jQuery("#buyertown").val();

    var buyerregion = jQuery("#buyerregion").val();

    var buyercountry = jQuery("#buyercountry").val();

    var buyerpostalcode = jQuery("#buyerpostalcode").val();

    var buyercontact = jQuery("#buyercontact").val();

    var buyermobile = jQuery("#buyermobile").val();

    var buyeremail = jQuery("#buyeremail").val();

    var buyerprefpay = jQuery("#buyerprefpay").val();

    var buyerspecreq = jQuery("#buyerspecreq").val();

    var adminemail = jQuery("#adminemail").val();

    var adminstorename = jQuery("#adminstorename").val();

 

    var datastring = 'div=' + diver +  '&buyersalute=' + buyersalute + '&buyerfirstname=' + buyerfirstname + '&buyerlastname=' + buyerlastname + '&buyerstreet=' + buyerstreet + '&buyertown=' + buyertown + '&buyerregion=' + buyerregion + '&buyercountry=' + buyercountry + '&buyerpostalcode=' + buyerpostalcode + '&buyercontact=' + buyercontact + '&buyermobile=' + buyermobile + '&buyeremail=' + buyeremail + '&buyerprefpay=' + buyerprefpay + '&buyerspecreq=' + buyerspecreq + '&adminemail=' + adminemail + '&adminstorename=' + adminstorename;

 

 

    jQuery.ajax({

            type: "POST",

            url: "http://www.domain.com/php/email.php",

            scriptCharset: "utf-8",

            contentType: "application/x-www-form-urlencoded; charset=UTF-8",

            data: datastring,

            success: function(data) {alert(data);}

        });

        eraseCookie('storeCookie');

};

Link to comment
Share on other sites

Hi,

here is some stuff i been trying out. I cant get it to work-- i don't even get an error cause the server doesn't recognize my script :D. Please all i want to do is post this variables to the email.php page.

if you can you see something wrong here please correct it.

 

 

me.emailCheckout = function() {

    var div = me.updateCartView( document.createElement("diver") );

    diver = "<div class='globalStoreCart_items'>" + div.innerHTML + "</div>";

    var buyersalute = getElementById("buyersalute");

    var buyerfirstname = getElementById("buyerfirstname");

    var buyerlastname = getElementById("buyerlastname");

    var buyerstreet = getElementById("buyerstreet");

    var buyertown = getElementById("buyertown");

    var buyerregion = getElementById("buyerregion");

    var buyercountry = getElementById("buyercountry");

    var buyerpostalcode = getElementById("buyerpostalcode");

    var buyercontact = getElementById("buyercontact");

    var buyermobile = getElementById("buyermobile");

    var buyeremail = getElementById("buyeremail");

    var buyerprefpay = getElementById("buyerprefpay");

    var buyerspecreq = getElementById("buyerspecreq");

    var adminemail = getElementById("adminemail");

    var adminstorename = getElementById("adminstorename");

 

var xmlhttp;

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById("theResponce").innerHTML=xmlhttp.responseText;

    }

  }

xmlhttp.open("POST","email.php",true);

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

xmlhttp.send("div=diver&buyersalute=buyersalute&buyerfirstname=buyerfirstname&buyerlastname=buyerlastname&buyerstreet=buyerstreet&buyertown=buyertown&buyerregion=buyerregion&buyercountry=buyercountry&buyerpostalcode=buyerpostalcode&buyercontact=buyercontact&buyermobile=buyermobile&buyeremail=buyeremail&buyerprefpay=buyerprefpay&buyerspecreq=buyerspecreq&adminemail=adminemail&adminstorename=adminstorename");

};

Link to comment
Share on other sites

Here is my full code:

 

email.php

 

<?PHP 

if( !isset($_POST['div']) ){
echo "No items selected";
return;
}	
$div = $_POST['div'];
$buyersalute = $_POST['buyersalute'];
$buyerfirstname = $_POST['buyerfirstname'];
$buyerlastname = $_POST['buyerlastname'];
$buyerstreet = $_POST['buyerstreet'];
$buyertown = $_POST['buyertown'];
$buyerregion = $_POST['buyerregion'];
$buyercountry = $_POST['buyercountry'];
$buyerpostalcode = $_POST['buyerpostalcode'];
$buyercontact = $_POST['buyercontact'];
$buyermobile = $_POST['buyermobile'];
$buyeremail = $_POST['buyeremail'];
$buyerprefpay = $_POST['buyerprefpay'];
$buyerspecreq = $_POST['buyerspecreq'];
$adminemail = $_POST['adminemail'];
$adminstorename = $_POST['adminstorename'];

$ADMIN_EMAIL 	= "'.$adminemail.'"; 
$EMAIL_SUBJECT 	= "'.$adminstorename.': '.$buyersalute.' '.$buyerlastname.' has placed an order.";
$BUYER_EMAIL 	= "'.$buyeremail.'"; 
$BUYEREMAIL_SUBJECT 	= "Hello '.$buyersalute.' '.$buyerlastname.' your order details.";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: <' . $ADMIN_EMAIL . ">\r\n";
$headers .= "From: \"domain.com\" <https://www.domain.com> \r\n";

$body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">

<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\">

<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" . $EMAIL_SUBJECT . "</title></head><body><table cols="2" width="100%">
<tr>
<td colspan="1">Name:</td> <td colspan="1">".$buyersalute." ".$buyerfirstname." ".$buyerlastname."</td></tr><tr>
<td colspan="1">Store Name:</td><td colspan="1">".$adminstorename."</td></tr><tr>
<td colspan="2">Address details:</td></tr><tr>
<td colspan="1">Street:</td> <td colspan="1">".$buyerstreet."</td></tr><tr>
<td colspan="1">Town: </td> <td colspan="1">".$buyertown."</td></tr><tr>
<td colspan="1">Region:</td> <td colspan="1">".$buyerregion."</td></tr><tr>
<td colspan="1">Country:</td> <td colspan="1">".$buyercountry."</td></tr><tr>
<td colspan="1">PostalCode:</td> <td colspan="1">".$buyerpostalcode."</td></tr><tr>
<td colspan="2">Contact Details:</td></tr><tr>
<td colspan="1">Email:</td> <td colspan="1">".$buyeremail."</td></tr><tr>
<td colspan="1">Phone:</td> <td colspan="1">".$buyercontact."</td></tr><tr>
<td colspan="1">Mobile:</td> <td colspan="1">".$buyermobile."</td></tr><tr>
<td colspan="2">Special Requests:</td></tr><tr>
<td colspan="1">Prefered Payment Method:</td> <td colspan="1">".$buyerprefpay."</td></tr><tr>
<td colspan="2">Special Requests:</td></tr><tr>
<td colspan="2">".$buyerspecreq."</td></tr><tr>
<td colspan="2">Order Details:</td></tr><tr>
<td colspan="2">".$div."</td></tr><tr>
</tr></table></body></html>";
$subject = $EMAIL_SUBJECT;

mail( $ADMIN_EMAIL, $subject, $body, $headers);
mail( $BUYER_EMAIL, $buyersubject, $body, $headers);

echo "Success! Thank you '.$buyersalute.' '.$buyerlastname.' your order has been placed.<br>A copy of the order details were also sent to this email address: '.$BUYER_EMAIL.'";


?>


 

 

Ajax call:

 

 

<script>

me.emailCheckout = function() {

    var div = me.updateCartView( document.createElement("diver") );

    diver = "<div class='globalStoreCart_items'>" + div.innerHTML + "</div>";

    var buyersalute = getElementById("buyersalute");

    var buyerfirstname = getElementById("buyerfirstname");

    var buyerlastname = getElementById("buyerlastname");

    var buyerstreet = getElementById("buyerstreet");

    var buyertown = getElementById("buyertown");

    var buyerregion = getElementById("buyerregion");

    var buyercountry = getElementById("buyercountry");

    var buyerpostalcode = getElementById("buyerpostalcode");

    var buyercontact = getElementById("buyercontact");

    var buyermobile = getElementById("buyermobile");

    var buyeremail = getElementById("buyeremail");

    var buyerprefpay = getElementById("buyerprefpay");

    var buyerspecreq = getElementById("buyerspecreq");

    var adminemail = getElementById("adminemail");

    var adminstorename = getElementById("adminstorename");

 

var xmlhttp;

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById("theResponce").innerHTML=xmlhttp.responseText;

    }

  }

xmlhttp.open("POST","email.php",true);

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

xmlhttp.send("div=diver&buyersalute=buyersalute&buyerfirstname=buyerfirstname&buyerlastname=buyerlastname&buyerstreet=buyerstreet&buyertown=buyertown&buyerregion=buyerregion&buyercountry=buyercountry&buyerpostalcode=buyerpostalcode&buyercontact=buyercontact&buyermobile=buyermobile&buyeremail=buyeremail&buyerprefpay=buyerprefpay&buyerspecreq=buyerspecreq&adminemail=adminemail&adminstorename=adminstorename");

};

 

</script>

 

Link to comment
Share on other sites

Hi kevin.

I got the posting script running turns out at the end of the day that this part of the script was not working.

 

    var div = me.updateCartView( document.createElement("diver") );

    diver = "<div class='StoreCart_items'>" + div.innerHTML + "</div>";

 

The strange thing is it works on the original demo script on its own, But loaded into my site and with my own tweks it does nothing. I naturally assumed it was Jquery, cause including the jquery was the only difference between my script in my web page DOM. and the demo version of the script..

 

this part:

me.updateCartView( //is a ready function to update the cart. This i know works cause my cart is updated when i select something.

 

and this part when i add 2 "\" it allows the script to pass but does not pass the cart values only passes->  \"+div.innerHTML+\"

here is where i add the 2 "\"        _items'>\" + div.innerHTML + \"</div>";

 

//without it the post doesnt reach the email send. and with it the values do not pass.

Do you know another way to write this two lines. Or do you need more information.

Regards

Tony

Link to comment
Share on other sites

Hi kevin.

I got the posting script running turns out at the end of the day that this part of the script was not working.

 

    var div = me.updateCartView( document.createElement("diver") );

    diver = "<div class='StoreCart_items'>" + div.innerHTML + "</div>";

 

The strange thing is it works on the original demo script on its own, But loaded into my site and with my own tweks it does nothing. I naturally assumed it was Jquery, cause including the jquery was the only difference between my script in my web page DOM. and the demo version of the script..

 

this part:

me.updateCartView( //is a ready function to update the cart. This i know works cause my cart is updated when i select something.

 

and this part when i add 2 "\" it allows the script to pass but does not pass the cart values only passes->  \"+div.innerHTML+\"

here is where i add the 2 "\"        _items'>\" + div.innerHTML + \"</div>";

 

//without it the post doesnt reach the email send. and with it the values do not pass.

Do you know another way to write this two lines. Or do you need more information.

Regards

Tony

 

These two lines:

 

var div = me.updateCartView( document.createElement("diver") );
diver = "<div class='StoreCart_items'>" + div.innerHTML + "</div>";

 

Don't make any sense.  document.createElement() takes a tag name as an argument, meaning something along the lines of 'div', 'a', 'span', etc.  With this code, you're trying to create <diver></diver>, which is gibberish.

 

It looks like, without knowing what updateCartView() does, you want something like:

 

var div = document.createElement('div');
var cart = me.updateCartView(div);
cart.className = 'StoreCart_Items';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.