【发布时间】:2010-04-19 02:49:29
【问题描述】:
我知道 HTML 中的提交按钮可以提交打开目标页面的表单,但是我如何导致 jQuery ajax 调用将信息发布到新页面并显示新页面。我正在提交通过单击元素(切换名为“select”的新类)收集的信息,然后将这些项目的标识符与新类添加到字符串中并发布到新页面。这个新页面将使用此数据提供上一页选择的摘要。我目前可以让它将数据发布到一个新的 PHP 页面,但它似乎是 ajax 函数只是保留在当前页面上(这对某些事情来说很好,只是不是这个),而不是重定向到新页面。我该怎么做呢?
这是脚本部分:
//onload function
$(function() {
//toggles items to mark them for purchase
//add event handler for selecting items
$(".line").click(function() {
//get the lines item number
var item = $(this).toggleClass("select").attr("name");
});
$('#process').click(function() {
var items = [];
//place selected numbers in a string
$('.line.select').each(function(index){
items.push($(this).attr('name'));
});
$.ajax({
type: 'POST',
url: 'additem.php',
data: 'items='+items,
success: function(){
$('#menu').hide(function(){
$('#success').fadeIn();
});
}
});
});
return false;
});
任何指针都会很棒!谢谢
编辑: 感谢您的帮助,我已将脚本更改为:
//onload function
$(function() {
//toggles items to mark them for purchase
//add event handler for selecting items
$(".line").click(function() {
//get the lines item number
var item = $(this).toggleClass("select").attr("name");
});
$('#process').click(function() {
var items = [];
//place selected numbers in a string
$('.line.select').each(function(index){
items.push($(this).attr('name'));
});
$('#items').attr('value',items);
$('#form').submit()
});
return false;
});
【问题讨论】:
标签: javascript jquery html forms