0
I am developing a form via ajax/php, when I click on the desired item the form sends the data to ajax and displays in div, but I need to return a value but I am not getting.
JS:
//script do form
$("#copPasta").focus(function(){
var val = new Array();
$('.check:checked').each(function(){
val.push($(this).val());
});
$.ajax({
url:'copPasta.php',
type:'GET',
data:'valor=' + val,
success:function(data){
$('.exibeCopPasta').html(data);
}
});
return false;
});
PHP:
<?php //ajax
if( isset( $_GET['valor'] ) ){
$a = explode(',' , $_GET['valor']);
foreach( $a as $value ){
$a_value = explode('/' , base64_decode($value));
$f_value = array_pop($a_value);
echo $f_value."<br />";
//gera array descriptografado
$array[] = base64_decode($value);
}
}
$c = 1;
return $c;
?>
$c in php I would need to confirm the reading and enable the function, then then in the main form if it is set the $c variable performs the copy function. What I’m doing wrong?
Maybe not the best practice, but instead
return
use theecho
– Mike
Checking that if the variable is set is on the same ajax page?
– Guilherme Lopes
You need to
$c
, Isn’t that right? From what I understand of your comment: return the value with echo and then check the ajax page– Mike
then, I have the form as main, and an ajax call to treat and return in a div, but I need to return a variable $c, by echo I can’t validate in a form, it can be via get, post, anything, but I need to return some value in a variable coming from ajax.
– Bruno Depieri Barduchi
You absolutely need to use echo. With Return ajax does not take the return.
– Guerra
As I said before, use
echo
whatever you want to return.Anything "displayed in php" will return to the variabledata
js as plain text.I would recommend setting the Reply header and working with json.– Pedro Erick
It may not be best practice, but I found a way. <input type="Hidden" value="c" name="action" /> I applied inside php after ajax and was able to redeem via $_REQUEST
– Bruno Depieri Barduchi
That one
data:'valor=' + val,
is to be a single string ?– ayelsew
Commonly used date: {value: val} where "value" will be the name of the key in the array on the server side and when called "$_GET['value']" will be returned from the value passed by the val variable on the front end side
– ayelsew