jQuery – Ajax showing empty RESPONSE / Success: not triggered when used with WordPress posts and pages

Any help would be appreciated.

I have created a small script which works fine when used with simple php pages. Now I just tried to add this script to my WordPress posts and pages. So I used “exec-php” plugin to call the php script.

Read More

Everything works fine. But when user fills the data and submits the form, the data actually gets submitted (I can see the posted variables in firebug), but the response is not displayed under the form when used with wordpress, where as it works fine when used with plain php pages.

My jQuery code is like this:

var dataString = 'name=' + name + '&country=' + country + '&lang=' + language;

$("#paypal-submit").click(function () {

    $.ajax({
        type: "POST",
        url: "get.php",
        data: dataString,
        dataType: 'html',
        success: function (gotresponse) {
            $('#response-id').html("<div id='id-message'><p>Got Response</p></div>");
            $('#id-message').html(gotresponse).fadeIn(1500, function () {
                $('#id-message');
            });
            $('#name').attr('onchange', 'resetForm()');
            $('#country').attr('onchange', 'resetForm()');
        }
    });
});

When I actually view the whole process in firebug, I can see that the data is actually posted to the server.

200 OK               2.03s

But when I see the response tab in firebug console, it is empty. I think the success message is not getting triggered when used with WordPress.

I cant figure out what could be the problem? Can someone help me solve this?

NOTE: The same script works fine when used as it is, but when used with WordPress the jQuery – Ajax success does not get triggered.

1st Edit:

I just included the error: in ajax function

error:function(x,e){
            if(x.status==0){
            alert('You are offline!!n Please Check Your Network.');
            }else if(x.status==404){
            alert('Requested URL not found.');
            }else if(x.status==500){
            alert('Internel Server Error.');
            }else if(e=='parsererror'){
            alert('Error.nParsing JSON Request failed.');
            }else if(e=='timeout'){
            alert('Request Time out.');
            }else {
            alert('Unknow Error.n'+x.responseText);
            }
        }

Now when I submit the form I get the alert saing “You are offline!! Please Check Your Network.” This error is getting triggered. So please help me now.

Related posts

Leave a Reply

1 comment