答案 0 :(得分:6)
// Event handler for when you click the button
$("button.save").click(function () {
var codes = [];
// For each of your li's with a code attribute
$("li[code]").each(function () {
// Stuff the code into an array
codes.push($(this).attr("code"))
});
// You can't post an array, so we turn it into a comma separated string
codes = codes.join();
// Do a post request to your server resource
$.post("/path-to-your-php-code/", {"codes" : codes}, function (response) {
// Handler for successful post request
alert("The ajax request worked!");
});
});
您还需要解析php中的代码字符串,这些代码将在
中提供$_POST["codes"];
答案 1 :(得分:0)
$.post('url.php', {
li1:$("li:eq(0)").text(),
li2:$("li:eq(1)").text(),
li3:$("li:eq(2)").text()}, function(){
alert('done');
});
答案 2 :(得分:0)