[英]jQuery Ajax POST request
I am trying to get the following code to send variables to a PHP page via POST. 我正在尝试获取以下代码,以通过POST将变量发送到PHP页面。 I am not quite sure how to do it.
我不太确定该怎么做。 This is my code sending data via GET and receiving it via JSON encoding.
这是我的代码通过GET发送数据并通过JSON编码接收数据。 What do I need to change to pass variables to process_parts.php via POST?
我需要更改什么才能通过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();
The default method is GET
, to change that, use the type
parameter. 默认方法是
GET
,要更改此type
,请使用type
参数。 You can also provide your querystring properties as an object so that they are not immediately obvious in the URL: 您还可以将querystring属性作为对象提供,以使它们在URL中不会立即变得明显:
var url = "process_parts.php";
$.ajax({
url: url,
type: 'POST',
data: {
offset: offset,
limit: limit
}
}).done(function() {
// rest of your code...
});
Try This 尝试这个
$.ajax({
url: "URL",
type: "POST",
contentType: "application/json;charset=utf-8",
data: JSON.stringify(ty),
dataType: "json",
success: function (response) {
alert(response);
},
error: function (x, e) {
alert('Failed');
alert(x.responseText);
alert(x.status);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.