Javascript jQuery获取输入框文本并使用$post发送到php
谁能告诉我怎么做?Javascript jQuery获取输入框文本并使用$post发送到php,javascript,php,jquery,Javascript,Php,Jquery,谁能告诉我怎么做? 我使用按钮在文本输入框中输入数据。之后,我想按建议使用的方式单击b 基本语法如下所示: $.ajax({ url: '/path/to/file', type: 'default GET (Other values: POST)', dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)', data: {param1: 'value1'} }) .don
我使用按钮在文本输入框中输入数据。之后,我想按建议使用的方式单击b 基本语法如下所示:
$.ajax({
url: '/path/to/file',
type: 'default GET (Other values: POST)',
dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
data: {param1: 'value1'}
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
在您的情况下,这可以简化一点:
$("#add").click(function() {
$.ajax({
url: '/path/to/file',
type: 'POST',
data: {currentTotal: $display.val()},
success: function(result){
// here you will have access to the response from your PHP script
// and can do something with it
}
});
});
在PHP脚本中,您可以访问发布的值,因此:
<?php
$currTot = $POST['currentTotal'];
您可以创建一个ajax调用post类型(我看到您使用jquery),那么$.ajax或$.post也可以发布HTML吗?
<?php
$currTot = $POST['currentTotal'];
// do some processing to obtain $newTotal
echo $newTotal