samedi 18 avril 2015

Appending http_build_query() response to URL when using php array

I'm posting an array of values from a group of checkboxes to a page using ajax and then building an url to send a GET request to another page. My jquery looks like so:



$('#compareRowButton').on('click', function() {
var cells = dTable.cells( ).nodes();
var post_ids = [];
$.each(cells, function(i, e){ // iterate each row
var checkbox = $(e).find('input.compareCheck'); // find the checkbox
if(checkbox.is(':checked')) { // if this checkbox is checked
var post_id = checkbox.attr('value'); // get the value
post_ids.push(post_id); // push it inside the container
}
});
//console.log(post_ids);
$.ajax({
url: 'query/httpbuild.php',
type: 'POST',
data: {post_id: post_ids},
success: function(response) {
alert(response);
window.location.replace("comparables/compare_baddebt.php?post_id[]" + reponse); // appending the array data to the url
}
});
});


My php httpbuild.php looks like this:



<?php
//accepts POST_ID as array and parses into URL for comparables GET REQUEST
if(isset($_POST['post_id'])){
$in = $_POST['post_id'];
}
echo http_build_query($in);
exit();


Currently if I push the #compareRowButton with the first two rows selected, it alerts me with 0=1$1=2 which I think is correct, but I don't think I'm appending it correctly to window.location.replace("comparables/compare_baddebt.php?post_id[]" + reponse);


As I get the error uncaught reference error: response is undefined in my console. How can I properly add the array values to the URL that I am trying to send the GET request with?


Thanks in advance


Aucun commentaire:

Enregistrer un commentaire