javascript之jQuery Ajax POST 请求
unruledboy
阅读:35
2025-12-25 22:24:30
评论:0
我正在尝试获取以下代码以通过 POST 将变量发送到 PHP 页面。我不太确定该怎么做。这是我的代码通过 GET 发送数据并通过 JSON 编码接收数据。我需要更改什么才能通过 POST 将变量传递到 process_parts.php?
function imagething(){
var done = false,
offset = 0,
limit = 20;
if(!done) {
var url = "process_parts.php?offset=" + offset + "&limit=" + limit;
$.ajax({
//async: false, defaults to async
url: url
}).done(function(response) {
if (response.processed !== limit) {
// asked to process 20, only processed <=19 - there aren't any more
done = true;
}
offset += response.processed;
$("#mybox").html("<span class=\"color_blue\">Processed a total of " + offset + " parts.</span>");
alert(response.table_row);
console.log(response);
imagething(); //<--------------------------recursive call
}).fail(function(jqXHR, textStatus) {
$("#mybox").html("Error after processing " + offset + " parts. Error: " + textStatus);
done = true;
});
}
}
imagething();
请您参考如下方法:
默认方法是GET,要更改它,请使用type 参数。您还可以将查询字符串属性作为对象提供,以便它们在 URL 中不会立即明显:
var url = "process_parts.php";
$.ajax({
url: url,
type: 'POST',
data: {
offset: offset,
limit: limit
}
}).done(function() {
// rest of your code...
});
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。



