Zrobiłem responsywny formularz, który w zależności od tego czy jest wyświetlany na małym ekranie czy na dużym pokazuje lub ukrywa pewne pola tagi html.
Problem w tym że jak wysyłam dane ajaxem to dostaję błąd 500 i w Firebugu w zakładce POST widzę że wraz z danymi wysłanymi idą puste dane z inputów, które powinny być niewidoczne dla skryptu.
Jak zakomentuję inputy, które nie powinny być widoczne to skrypt działa bez problemu i wysyła dane.
Co robię źle lub co jeszcze powinienem dopisać aby skrypt działał ?
HTML:
...
{% else %}
<table class="tab_types"> {% for key,meet in meets %}
<input type="hidden" name="meet_id[]" value="{{ meet.meet_id }}" /> <td class="desc">{{ meet.league }}
</td> <td class="host">{{ meet.host }}
</td> <td class="type"><input type="text" class="tp" name="hostType[]" maxlength='1'></td> <td class="type"><input type="text" class="tp" name="guestType[]" maxlength='1'></td> <td class="guest">{{ meet.guest }}
</td> <td class="term">{{ meet.term }}
</td>
<tr class="small_screen"> <td class="position">{{loop.index}}.
</td> {{ meet.host }}
<input type="text" class="tp" name="hostType[]" maxlength='1' />
<tr class="small_screen"> <td class="position"></td> {{ meet.guest }}
<input type="text" class="tp" name="guestType[]" maxlength='1' /> {% endfor %}
<td><input type="submit" value="Wyślij" class="space"/></td> {% endif %}
<script type="text/javascript"> $(function(){
$("#form").submit(function(e){
var form=$(this);
$.ajax({
url:"{{ path('liga_typerow_types') }}",
dataType:"JSON",
type:"POST",
data:form.serialize(),
success:function(){
form.get(0).reset();
console.log("jest ok");
location.reload();
},
error: function() {
console.log("Wystąpił błąd");
}
});
e.preventDefault();
});
});
CSS:
/* USTAWIENIA DLA KAŻDEGO EKRANU */
table.tab_types {
width: 100%;
/*border-collapse: collapse;*/
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: center;
}
input[type="text"].tp {
width: 10px;
}
/* USTAWIENIA DLA DUŻEGO EKRANU */
@media screen and (min-width:680px) {
/* niewidoczne */
tr.small_screen{
display: none;
}
tr:nth-of-type(odd) {
background: #eee;
}
}
/* USTAWIENIA DLA MAŁEGO EKRANU */
@media screen and (max-width:680px) {
/* niewidoczne */
tr.big_screen,td.term,td.desc,
tr.col_name,td.gap,td.host,
td.guest,td.type {
display: none;
}
/* widoczne */
td.position{
width: 10%;
}
td.team_name{
text-align: left;
width: 80%;
}
td.user_type{
width: 10%;
}
tr.small_screen:nth-of-type(3n) {
background: #eee;
}
}
POST widoczny w Firebugu:
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
guestType[]
1
guestType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
hostType[]
1
hostType[]
meet_id[]
1
meet_id[]
2
meet_id[]
3
meet_id[]
4
meet_id[]
5
meet_id[]
6
meet_id[]
7
meet_id[]
8
meet_id[]
9
meet_id[]
10