Ajax and jQuery with PHP
Ajax and jQuery with PHP
我有这段代码,它使用jQuery和ajax将数据发布到自身。
<input type="button" id="butt" value="button11111111111111" >
<script>
$("#butt").on('click',function(e)
{
$.ajax(
{
type:'POST',
url:'test.php',
data:product_type:"cake"
});
});
</script>
<?php
if(isset($_POST['product_type']))
$abc=$_POST['product_type'];
if(isset($abc))
echo $abc;
?>
现在,当我尝试运行此代码时。我确实在 Chrome 的网络控制台中获得了正常状态,但此代码不会回显输出。
我只想显示 ajax 方法传递的结果。
我是 ajax 和 jquery 的新手,所以我不太了解它们的工作原理,但这可能吗?如果是,那么如何在不实际刷新页面的情况下实现这一目标?
这是我认为你想要的,即测试.php是源页面和 ajax 页面!
<?php
if(isset($_POST['product_type'])) {
Header("Content-type: text/plain; charset=utf-8");
$abc=$_POST['product_type'];
if(isset($abc)) {
echo $abc;
}
}
else {
?>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<input type="button" id="butt" value="button11111111111111" >
<script>
$("#butt").on('click',function(e) {
$.ajax({
type:'POST',
url:'test.php',
data: {
product_type:"cake"
},
success: function(data) {
alert('got ' + data);
}
});
});
</script>
</html>
<?php
}
?>
相关文章:
- timeago.js with datatable and PHP
- PHP $_GET with jQuery $.get call
- PHP Error with Javascript
- JavaScript with PHP SESSION
- Ajax Call with Post in PHP
- chartJs with MySQL and PHP
- HTML用PHP替换with函数
- InnerHTML with PHP
- Ajax call VERY SLOW with PHP
- jQuery load with php in it?
- Wordpress: POST to .php with Ajax
- Javascript array to PHP with json.stringify
- Call PHP with JavaScript
- js/php with include files
- Javascript array to php with jQuery ajax
- PHP with Javascript - What is the scope of PHP variables ins
- PHP with javascript
- Using TeeChart PHP with javascript
- GET id from php with javascript
- Javascript value to PHP with Jquery