How to clear ajax answer

I have an event from which I call the Ajax function. From this ajax function, I want to return a string, but the problem is that the function also calls some other functions and returns some value.

The problem is that the ajax called page returns all the sting that comes back from each function, I mean Inherited.

Ajax Event:

$(".close_some").on("click", function(){ $.get("close_some.php", { id : data_id, close_date_time : close_date_time }, function(response){ console.log(response); if(response === "success"){ document.location.reload(true); }else{ alert('Some problem'); } }); }); 

close_some.php

 $col = someFunction($id); //this function also called another function where a return statement works include_once "some_page.php"; echo 'success'; 

SomeFunction ()

 function someFunction($id){ $sql = "SELECT `demo` FROM `some_problems` WHERE id = '$id'"; ... return departmentName($dept_id); } 

Now, when I see its long line in response , but I only need success , how can I delete other answers

Thanks at Advance.

+5
source share
3 answers

You can buffer the output of some_page.php using the output control functions as follows:

 ob_start(); $col = someFunction($id); include_once "some_page.php"; ob_end_clean(); echo 'success'; 
+4
source

It seems you are echoing or returning threads from some functions that you are calling from this. You should not echo values ​​/ strings directly from functions.

The solution to your problem is the ob_start and ob_end_clean() functions.

to make your code look.

 <?php ob_start(); $col = someFunction(....); //this function also called another function where a return statement works include_once "some_page.php"; ob_end_clean(); echo 'success'; 
+1
source

It is not possible for the ajax repository to return a value like Buffer , it is better to check if you have echo functions or not, I'm sure that you have an echo in someFunction .

We use ob_start() to store the output as a buffer, I don’t think you are doing this in your code.

If your function does not have an echo, just use ob_end_clean() before echo "success"; .

I think there are some answers that are informative for you, all the best.

+1
source

All Articles