Prev | Current Page 513 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

statusText);
}
}
}
In practice, we will be displaying more user-friendly error messages. Moreover, whenever
possible, we??™ll make our code degradable so that when an error happens inside the JavaScript
code, the functionality is instead performed using a typical form submit. Let??™s see how.
Writing Degradable Code
Ideally, a modern web application should use AJAX to enhance existing features whenever
possible, while keeping the web site functional even when JavaScript isn??™t available. In our
particular case, we want to let our visitors add products to their shopping carts and edit their
shopping carts even if they have JavaScript disabled or if their web browser doesn??™t support
JavaScript.
When a visitor clicks the Add to Cart button, we first try to make a background AJAX call
to add the product to the visitor??™s cart and update the cart summary box accordingly. If an
error happens when trying to make the call or if JavaScript is disabled, we submit the form to
the server and add the product to the visitor??™s cart in a non-AJAX fashion. This way, we??™ll offer
a better web experience to most of our users, while permitting the others to use our store as well.
This is easier to implement than it sounds. Take a look at the following code, which represents
the AJAXified ???Save for later??? and Remove links in the shopping cart.


Pages:
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
zakłady bukmacherskie przeszycia łódź czlowiek.cieszyn.pl wróżby miłosne poker