#javascript #jquery #ajax
#javascript #jquery #ajax
Вопрос:
Я должен опубликовать формы с помощью метода post в jquery, каков правильный синтаксис?
Модулей a, b, c несколько. Я должен отправить все через post и получить ответ через alert.
Это мой код:
<input type="text" name="type">
<input type="text" name="model">
<input type="text" name="a[]">
<input type="text" name="b[]">
<input type="text" name="c[]">
<input type="text" name="a[]">
<input type="text" name="b[]">
<input type="text" name="c[]">
$('#start').click(function(){
var type = $('input[name=type]').val()
var model = $('input[name=model]').val()
var a = [];
$('input[name="a[]"]').each(function() {
a.push($(this).val());
});
var b = [];
$('input[name="b[]"]').each(function() {
b.push($(this).val());
});
var c = [];
$('input[name="c[]"]').each(function() {
c.push($(this).val());
});
var send = .....({
type:type:,model:model,a:a,b:b,c:c
});
$.ajax({
url: '.post.php',
type: 'POST',
data: {send:send},
success: function(data) {
//alert(data);
}
});
Комментарии:
1. Обратите внимание, что вы должны удалить последнее
:
вtype:type:
Ответ №1:
Попробуйте что-то вроде:
var send = function() {
return {
type:type,
model:model,
a:a,
b:b,
c:c
};
});
$.ajax({
url: 'post.php',
type: 'POST',
data: {send:send()},
success: function(data) {
alert(data);
}
});