Jump to content

Dados com PHP e JSON


jonhyhvaftn
 Share

Go to solution Solved by tiago.f,

Recommended Posts

Boas, tenho o seguinte código:

$query = "SELECT * FROM users WHERE user='".$_POST['user']."' AND password='".$_POST['password']."'";
$result = $link->query($query);
$yes = $result->num_rows;
json_encode({"result": $yes});

$.ajax({
	    url: "vlogin.php",
	    cache: false,
	    dataType: "json",
	    success: items += result;
		   $("#loginMain").html(items);

    });

Infelizmente na página index.html que é onde está o ajax nada é retornado, sendo que a variável $yes contem um número.

Estou a fazer algo mal?

Link to comment
Share on other sites

A função não deve ter nome e deve receber (até) 3 parametros.

Põe exactamente o código que eu escrevi antes e vê o que aparece na consola..

"success callback option is invoked, if the request succeeds. It receives the returned data(1), a string containing the success code(2), and the jqXHR object(3)."--> http://api.jquery.com/jquery.ajax/

É também é importante:

"Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead."

Edited by tiago.f
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.