ajax按钮的写法,jQuery Ajax调用列表上的按钮

$(document).ready(function(){

//this will target all controls for all forms on the page. A better practice would be to focus on just the target forms

// perhaps based on the ID of a containing div, etc

$("form [input[@type=image]").click(function(){

//$image is now a jQuery object variable referencing the clicked image

var $image = $(this);

//$form is now a jQuery object variable referencing the parent

of the clicked image

var $form = $image.parent();

//stockId is now a variable referencing the id of the form, assuming this is the stockID we want to manipulate

var stockId = $form.attr("id");

//probably a better way to do this, but to know if we want to go up or down, I checked the src attribute of the control

//if the url of the image contains add, the direction is add, else it's del

var direction = $image.attr("src").contains("add") ? "add" : "del";

//call a function to handle the add,del

shiftStock(stockId, direction);

});

});

//a javascript function that accepts the ID of the stock and the direction we want to go

function shiftStock(stockId, direction){

//do an ajax call using jQuery, passing in our stockId and direction

//I'm using a get, but and an XML return data Type, but this could just as easily be a post with json, etc

$.ajax(

type: "GET",

url: "webserviceurl??",

dataType: "XML",

data: "stockId=" + stockId + "&direction=" + direction,

success: function(xml){

//parse the returned xml if need be to handle any UI updates, like new stock numbers, etc?

alert(xml);

},

error: function(xml, error, status){

alert(error);

}

);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值