I'm working with Codeigniter.
I need to access twice to a php function, but the first time I don't have to echo a json_encode array....I should echo it the second time when I call it from a js file. How do I do it?
So, php file:
function filter(){
if (function call is not from js file ) {
//using $_POST variable to get info from the form
dont echo json
}elseif (function call is from the js file) {
echo json_encode($data);
//but $data should be $_POST info too, but in this case $_POST WOULD
//BE EMPTY and I'm sending no data to ajax
}
}
from js file:
$.ajax({
type: "GET",
url: "filter",
dataType: 'json',
success: function(data){
alert(data); },
error: function(data){
alert('error'); }