2016-09-16 8 views
0

Ich habe dieses HTML-Formular, das Eingabewerte mit jQuery AJAX zu PHP sendet. Der Prozess lief gut, aber nur, wenn ich es sehe, wenn ich mit der rechten Maustaste klicke> inspect element> network> header. Leider bleibt die reale Seite still.HTML Form Senden von Werten mit jQuery Ajax zu PHP

ist es dort, ich habe es falsch gemacht? bitte hilfe. Vielen Dank, ich schätze die Hilfe sehr.

  • ich habe nicht die vollständigen Codes enthalten, weil ich glaube, ich habe auf der jQuery Ajax vermasselt, weil anscheinend der Prozess gut ging und korrektes Ergebnis zeigte

HTML FORM

<div class="product-filter-type"> 
        <input type="radio" class="checkFilter" id="filterAllTV" name="typeTV" value="AllTV" checked><label class="filterType" for="filterAllTV">All TV</label><br/> 
        <input type="radio" class="checkFilter" id="filterFHDTV" name="typeTV" value="FHD"><label class="filterType" for="filterFHDTV">FHD/HD</label><br/> 
        <input type="radio" class="checkFilter" id="filter4K" name="typeTV" value="FOURK"><label class="filterType" for="filter4K">4K</label> 
       </div> 

JAVASCRIPT/JQUERY/AJAX

var type; 


    $('input[name="typeTV"]').click(function(){ 
     if ($(this).is(':checked')) 
     { 
      type = $('input[name="typeTV"]:checked').val(); 
      sendType(type); 
     } 
    }); 



function sendType(type){ 

    $.ajax({ 
     type: 'POST', 
     url: "{{ base_url() }}product", 
     data: { 
      'type' : type 
     }, 
     success: {} 
    }); 

PHP (FUELPHP)

public function action_product() { 

    $this->set_meta_info($this->_meta_slug); 

    $input_data = \Input::param(); 

    if(count($input_data) > 0){ 

     $this->_filter($input_data); 

    }else{ 

     $this->_data_template['product'] = \Product\Productutil::get_product_data(); 
     $this->_data_template['AllTV'] = 'checked'; 

    } 

    return \Response::forge(\View::forge('pages::frontend/product_list.twig', $this->_data_template, FALSE)); 
} 

private function _filter($input_data) { 

    $this->set_meta_info($this->_meta_slug); 

    if (count($input_data) > 0) { 

     $type  = isset($input_data['type']) ? $input_data['type'] : null; 


     if ($type){ 

      $this->_data_template['product'] = \Pages\Filterutil::get_type_product($type); 
      $this->_data_template[$type] = 'checked'; 

     }elseif { ... } 

     return $this->_data_template; 
    } 

} 
+2

Was erwarten Sie zu passieren? Ihr gesamter Code sendet die AJAX-Anforderung und führt im Callback nichts aus, sodass sich nichts in der Benutzeroberfläche ändert. –

+0

Definieren Sie Ihre Frage? –

+0

In deinen Entwicklungswerkzeugen solltest du eine xhr Anfrage sehen, die Hauptseite ändert ihre Überschriften nicht – madalinivascu

Antwort

0

Ok ich habe es.

Ich habe

hinzugefügt
$this->_filter($input_data); 
     return json_encode($this->_data_template['product']); 

auf dem PHP-Teil und fügte hinzu:

success: function (response) { 

      var json = $.parseJSON(response); 

      for (idx= 0; idx< json.length; idx++) { 

       .... 

      } 
     } 
    }); 

Vielen Dank an alle, es zu schätzen wissen. Wie schließt man diese Frage?