[英]How to run PHP script in the back by a jquery button
I need to run some PHP code from a file when I click a button from jQuery. 当我从jQuery单击一个按钮时,我需要从文件中运行一些PHP代码。 This is the code I have:
这是我的代码:
$(document).ready(function(){
$("#btnSubmit").button().click(function(){
alert("button 1");
$.ajax({
url: 'releaseBackEnd.php',
type: 'POST',
async: false,
data: {},
dataType: 'xml',
error: function(){
alert('Error');
},
success: function(data){
//check error
alert("success!");
}
});
});
});
It shows the alert of "error". 它显示“错误”的警报。 I have the releaseBackEnd.php file in the same directory of the javascript file.
我有releaseBackEnd.php文件在javascript文件的同一目录中。
check the response in firebug console .. if u don't have firebug add it to your firefox using this link 检查firebug控制台中的响应..如果你没有firebug,请使用此链接将其添加到firefox
https://addons.mozilla.org/en-US/firefox/addon/1843/ https://addons.mozilla.org/en-US/firefox/addon/1843/
Change 更改
$("#btnSubmit").button().click(
to 至
$("#btnSubmit").click(
and check whether the php page is sending the response or not. 并检查php页面是否正在发送响应。
Try getting the error in the error callback function using the XMLHttpRequest. 尝试使用XMLHttpRequest在错误回调函数中获取错误。
error(XMLHttpRequest, textStatus) {
}
Try this code... 试试这个代码......
$(document).ready(function(){ $("#btnSubmit").bind('click',function() { alert("button 1"); $.ajax({ url: 'releaseBackEnd.php', type: 'POST', async: false, data: {}, dataType: 'xml', error: function(){ alert('Error'); }, success: function(data){ //check error alert("success!"); } }); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.