Fábio
Fábio

Reputation: 91

AJAX for searching posts wordpress

this is returning errors that occur when you try to load an url with [] in it(as far as I know)... I dont know why i am getting this errors... please help me correct the code below:

Errors: Warning: strpos() expects parameter 1 to be string, array given in C:...\query.php on line 1718 <<<
Warning: preg_split() expects parameter 2 to be string, array given in C:...\query.php on line 1719 <<<
Warning: Invalid argument supplied for foreach() in C:...\query.php on line 1720 <<<

$("#submit").live("click", function() {
$("#form").submit(function() {
    event.preventDefault();
    var teste=$(this).serialize();
    $.ajax({
        type: "POST",
        url: "./.../search.php",
        data: teste,
        success:function(data) {
            $("#index_content").html(data);
        }
    });
});
});

Edited version that works :)

$("#submit").live("click", function() {
$("#form").submit(function() {
    event.preventDefault();
    teste = $('#form').serialize();
    $.ajax({
        type: "POST",
        url: "./.../search.php",
        data: { 'album-features': teste },
        success:function(response) {
            $("#index_content").html(response);
        }
    });
});
});

Upvotes: 2

Views: 974

Answers (1)

Adib Aroui
Adib Aroui

Reputation: 5067

Since you are using wordpress, why not to use its built in ajax and send the request to admin-ajax.php. I see that you are sending it to search.php, which is not a good approach especially for security.

Write your php code to be executed in functions.php and add actions.

This page is containing in its answer the detailed way to do so: Dynamically changing navigation links (next and previous) in Wordpress via AJAX

good luck, I am here to assist you

Upvotes: 1

Related Questions