Problem with jQuery.ajax ()
Good afternoon,
I'm having a problem with the method jQuery.ajax () and ja walked laps here and did not find solution anywhere.
What happens is this, you have this code in functions.js:
- function login()
- {
- var user = jQuery("#user_login").val();
- var pass = jQuery("#pass_login").val();
- jQuery("section #login").effect("fade", 500);
- jQuery.ajax({
- type: "POST",
- url: "ws/login.php",
- dataType: "json",
- data: {
- user: user,
- pass: pass
- },
- success: function (data)
- {
- alert("data " + data);
- },
- error: function (data)
- {
- alert("data " + data.toString());
- }
- });
- }
And in functions.php i have:
- <?PHP
- if(isset($_POST['user']) && isset($_POST['pass']))
- {
- //Verificar na db se estas credenciais existem
- require_once '../include/connectDB.php';
- $db = ligacaoDB();
- $query = "SELECT NOME, SENHA, ID_UTILIZADOR, to_char(sysdate, 'yyyy/mm/dd hh24:mi:ss')
- from ADM_UTILIZADORES where ID_UTILIZADOR='$_POST[user]'";
- $result = oci_parse($db, $query);
- oci_execute($result);
- $sql = oci_fetch_array($result, OCI_NUM + OCI_RETURN_NULLS);
- if($sql)
- {
- session_start();
- $_SESSION['user'] = $_POST['user'];
- $_SESSION['name'] = $sql[0];
- $_SESSION['pass'] = $sql[1];
- $_SESSION['user_id'] = $sql[2];
- $_SESSION['session_start'] =$sql[3];
- echo json_response("Bem-Vindo" . $sql[0]);
- }
- }
- ?>
- <?php
- function json_response($message, $response = true) {
- return json_encode(
- array(
- 'response' => $response,
- 'message' => $message
- )
- );
- }
- ?>
With that, he always give back to me the error, and not know why. Will can help me?