[英]How to Send Jquery Ajax data on Same php Page?
hi i want to send javascript data via ajax to the same page in wordpress. 嗨,我想通过Ajax将javascript数据发送到wordpress中的同一页面。 Cannot fetch the data in testajax.php page. 无法获取testajax.php页面中的数据。 its shows Undefined index: name. 它显示未定义的索引:名称。 And how to send the data on same php page rather than testajax.php ? 以及如何在同一php页面而不是testajax.php上发送数据?
<script>
jQuery.ajax({
type: "POST",
url: 'http://localhost/projects/xxx/wordpress/wp-content/themes/xxx/testajax.php',
data: {name:'foo'},
success: function(data)
{
alert('success');
}
});
var foo = 'somename';
jQuery.ajax({
url:'yourUrl',
type: "POST",
data: {'name':foo},
success: function(data)
{
alert('success');
}
});
php 的PHP
<?php
if(isset($_POST['name'])){
//Do whatever you want
}else{
//Do whatever you want
}
?> ?>
jQuery.ajax({
url: "./_FILE_" // ./index.php for example
type: "POST",
data: {name:'foo'},
success: function(data)
{
alert('success');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.