Guest User

Untitled

a guest
Dec 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. function ajax_scripts(){
  2.  
  3. wp_enqueue_script( 'wbajax', get_template_directory_uri() . '/js/wiperblades.js', array('jquery'), true );
  4. wp_localize_script(
  5. 'wbajax', 'frontEndAjax',
  6. array(
  7. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  8. 'nonce' => wp_create_nonce('ajax_nonce')
  9. )
  10. );
  11.  
  12. }
  13. add_action( 'wp_enqueue_scripts', 'ajax_scripts' );
  14.  
  15.  
  16. function wiperblades_form() {
  17.  
  18. $wbform = '<form id="wiperblades" action="">';
  19. $wbform .= '<select name="manufacturer">';
  20. $wbform .= '<option value="">Select Manufacturer</option>';
  21. $wbform .= '<option value="1">Audi</option>';
  22. $wbform .= '<option value="2">BMW</option>';
  23. $wbform .= '</select>';
  24.  
  25. if( !empty( $_POST['manuf'] ) ) {
  26. echo $_POST['manuf'];
  27. }
  28.  
  29. $wbform .= '</form>';
  30.  
  31. return $wbform;
  32.  
  33. wp_die();
  34.  
  35. }
  36. add_action( 'wp_ajax_nopriv_wiperblades_form', 'wiperblades_form' );
  37. add_action( 'wp_ajax_wiperblades_form', 'wiperblades_form' );
  38.  
  39. $(".search-div select[name=manufacturer]").change( function(e) {
  40.  
  41. var manufacturer = $(".search-div select[name=manufacturer]").val();
  42.  
  43. jQuery.ajax({
  44. type: 'POST',
  45. data: {
  46. 'nonce': frontEndAjax.nonce,
  47. 'action': 'wiperblades_form',
  48. 'manuf': manufacturer
  49. },
  50. url: frontEndAjax.ajaxurl,
  51. success: function(msg){
  52. console.log(manufacturer);
  53. },
  54. error: function(ts) {
  55. console.log(ts.responseText);
  56. }
  57. });
  58.  
  59. });
Add Comment
Please, Sign In to add comment