开发者

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. 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.


check the response in firebug console .. if u don't have firebug add it to your firefox using this link

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.

Try getting the error in the error callback function using the 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!");

        }
    });

    });
 });

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜