p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 (http://p2p.wrox.com/book-professional-ajax-2nd-edition-isbn-978-0-470-10949-6-310/)
-   -   Chapter 4 - Prototype example. (http://p2p.wrox.com/book-professional-ajax-2nd-edition-isbn-978-0-470-10949-6/93898-chapter-4-prototype-example.html)

pet2x December 6th, 2014 10:59 AM

Chapter 4 - Prototype example.
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Prototype POST Example</title>
<script type="text/javascript"src="prototype.js"></script>
<script type="text/javascript">
//<![CDATA[
function sendRequest() {
var oOptions = {
method: "post",
parameters: sBody,
onSuccess: function (oXHR, oJson) {
saveResult(oXHR.responseText);
},
onFailure: function (oXHR, oJson) {
saveResult("An error occurred: " + oXHR.statusText);
}
};

var oRequest = new Ajax.Request("SaveCustomer.php", oOptions);
}

function saveResult(sMessage) {
var divStatus = document.getElementById("divStatus");
divStatus.innerHTML = "Request completed: " + sMessage;
}
//]]>
</script>
</head>
<body>
<form method="post" action="SaveCustomer.php"
onsubmit="sendRequest(); return false">
<p>Enter customer information to be saved:</p>
<p>Customer Name: <input type="text" name="txtName" value="" /><br />
Address: <input type="text" name="txtAddress" value="" /><br />
City: <input type="text" name="txtCity" value="" /><br />
State: <input type="text" name="txtState" value="" /><br />
Zip Code: <input type="text" name="txtZipCode" value="" /><br />
Phone: <input type="text" name="txtPhone" value="" /><br />
E-mail: <input type="text" name="txtEmail" value="" /></p>
<p><input type="submit" value="Save Customer Info" /></p>
</form>
<div id="divStatus"></div>
</body>
</html>
------------------

Why is this not working for me? I try this your code on my computer, it takes me to the process page save customer.php.
Please why is the ajax.request function not working.


All times are GMT -4. The time now is 12:02 PM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.