Okay background i am a js and ajax noob. I work mainly in php and mysql html 5, i decided to get with the times and stop having to reload the page for simple things.
I am trying to make a simple ajax request to a php file and print the result.
So on my page i have a text bax with the id password(leftover from another experiment)
a jquery ui tabs setup with a tab with the id galleries and a div with the id my-galleries. The idea is that upon click on the galleries tab the value of the password field is pulled and sent to the php file my-galleries.php and the result is printed to the div my-galleries and displayed.
The code:
<input type="password" id="password"/>
<div id="tabs">
<ul>
<li id="welcome"><a href="content/welcome.html">Welcome</a></li>
<li><a href="content/about.html">About</a></li>
<li><a href="#my-galleries" id="galleries">Galleries</a></li>
<li><a href="content/contact.html">Contact</a></li>
</ul>
<div id="my-galleries"></div>
</div>
Then the js
$("#galleries").click(function(){
$.ajax({
type : 'POST',
url : 'my-galleries.php',
dataType : 'json',
data: {
password : $('#password').val()
},
success: function(msg){
$("#my-galleries").html(msg)
}
})
});
Then the php
$password= $_REQUEST['password'];
$salt= uniqid();
$str= $salt.$password;
$hash= hash("sha512", $str);
echo $hash;
According to the tuts i have been reading it should work but it doesn’t. I cant figure it out.
Your problem is that you’re requesting JSON; your data is definitely not JSON. It’s plain text, so use the
'text'dataType: