admin 管理员组文章数量: 1086019
hi i want to send javascript data via ajax to the same page in wordpress. Cannot fetch the data in testajax.php page. its shows Undefined index: name. And how to send the data on same php page rather than 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');
}
});
hi i want to send javascript data via ajax to the same page in wordpress. Cannot fetch the data in testajax.php page. its shows Undefined index: name. And how to send the data on same php page rather than 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');
}
});
Share
Improve this question
edited Aug 28, 2013 at 13:05
Harsh
asked Aug 28, 2013 at 12:56
HarshHarsh
111 gold badge1 silver badge5 bronze badges
7
- I don't see the URL... Where are you sending your data ? Maybe this is the problem... – Mohamed Amine Commented Aug 28, 2013 at 12:59
- I hope u r still adapting to AJAX. This is pletely wrong. you have to have a url provided.. – thecodejack Commented Aug 28, 2013 at 12:59
- What does your console say? – tymeJV Commented Aug 28, 2013 at 12:59
- 3 Everyone... a blank URL means it submits to the same page, as OP wants. – tymeJV Commented Aug 28, 2013 at 13:00
- Please provide more code. Have you tried using Chrome's Developer Tools (F12) to check for Javascript syntax? – Christian Dechery Commented Aug 28, 2013 at 13:01
2 Answers
Reset to default 4var foo = 'somename';
jQuery.ajax({
url:'yourUrl',
type: "POST",
data: {'name':foo},
success: function(data)
{
alert('success');
}
});
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');
}
});
本文标签: javascriptHow to Send Jquery Ajax data on Same php PageStack Overflow
版权声明:本文标题:javascript - How to Send Jquery Ajax data on Same php Page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744071994a2528660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论