Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. hansford's post in How to call php function from ajax was marked as the answer   
    Since you are using international chars, use utf-8 for your encoding.
    $.ajax({ url: "get_id.php", type: "POST", dataType: "json", contentType: "application/x-www-form-urlencoded;charset=utf-8", data : {action: 'visitaValidacaoByUserAdmin', id_visita: 'id_visita', plano: 'plano', valido: 'valido'}, cache: false, success: function(response) { alert(response['message']); }  
    PHP page example:
    <?php error_reporting(E_ALL); ini_set('display_errors', 1); // set headers header("Content-Type: application/json; charset=utf-8"); if (isset($_POST['action'])) { // call function $ret = $_POST['action'](); // return result echo json_encode($ret); } function visitaValidacaoByUserAdmin() { return array("status" => "success", "message" => "A visita já foi validada...Obrigado"); }
  2. hansford's post in i need some help was marked as the answer   
    I just set it up on the same page for illustration purposes. 
    <?php error_reporting(E_ALL); ini_set('display_errors',1); if (isset($_POST['direction']) && !empty($_POST['temp'])) { $direction = $_POST['direction']; $temp = $_POST['temp']; if ( ! is_numeric($temp)) { $error[] = "Input is not a valid number."; } if ( ! isset($error)) { if ($direction == "ftc") { $temp_new = convert_temp($temp); echo "$temp degrees Fahrentheit is <b>$temp_new</b> degrees Celsius " ; } else { $temp_new = convert_temp($temp,true); echo "$temp degrees Celcius is <b>$temp_new</b> degrees Fahrentheit " ; } } else { foreach ($error as $err) { echo $err . '<br />'; } } } function convert_temp($temp, $celcius=false) { if ($celcius) { $ret = ($temp * 9/5) + 32; } else { $ret = ($temp - 32) * 5/9; } return round($ret,1); } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>convert</title> </head> <body> <form action="" method="post"> <select name="direction"> <option value="ftc" selected>Fahrenheit to Celsius </option> <option value="ctf">Celsius to Fahrenheit </option> </select> <input type="text" name="temp" size="6"/> <br/> <input type="Submit" value="Convert"/> </form> </body> </html>
  3. hansford's post in Trying to add a barcode to my page was marked as the answer   
    I don't know what you are trying to do, but PHP and JavaScript are two completely different languages and one has no knowledge that the other even exists.
    You can pass data to PHP through form fields, hidden and others or through ajax.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.