<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-12-17 17:11:47Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
I want to change some value in my database, pressing on picture on my page, using javascript and AJAX. How can I do it?
</div>
you can use xmlhttprequest, and the javascript :
var xhr = new XMLHttpRequest(); // Create new XHR
var url = 'http://sample.com/change.php'; // The url
var data = 'data=sample&back=come';
xhr.open('POST', url, true); // POST is method you can with `POST|GET`
xhr.send(data);
or it can be simplifer with jquery
var url = 'http://sample.com/change.php'; // The url
var data = 'data=sample&back=come';
$.post(url,data,function(callback){
alert(callback);
});
and sure bind it on your image:
$("img").click(function(){
var url = 'http://sample.com/change.php'; // The url
var data = 'data=sample&back=come';
$.post(url,data,function(callback){
alert(callback);
});
});
then the php file:
<?php
$post_data = mysql_real_escape_string($_POST['data']);
$post_back = mysql_real_escape_string($_POST['back']);
$query = mysql_query("UPDATE table SET data = '".$post_data."' WHERE `back` = '".$post_back."'"); // This is a query, change it with yours
if($query){echo'Success';} //Print a success message
?>
Finish, good luck