[eluser]RaZoR LeGaCy[/eluser]
[quote author="At the Gates" date="1227137379"]sorry, just updated my code above to
Code:
var target = $(this).children('img');
so that only the one you clicked on will change[/quote]
I tried your above code but when the image was clicked it went to the next page instead of creating ajax type request.
I then reverted back to my original code and it worked except the value was not getting captured and passed to the dev/update script.
Code:
<?php
class Dev extends Controller {
function dev() {
parent::Controller();
#$this->load->library('image_lib');
#$this->output->cache(5);
}
function index() {
//if(isAdmin()){ $this->output->enable_profiler(TRUE); }
$this->load->model('dev_model');
#Meta Data
$data['ptitle'] = '';
$data['pkeywords'] = '';
$data['pdesc'] = '';
$data['fsentence'] = '';
#Queries
#Body View
$data['body'] = $this->load->view('dev/dev',$data,true);
#Template == Never Change ==
$this->load->vars($data);
$this->load->view('inc/templates/dev', $data);
}
function update() {
$value = $this->input->post('value');
$raw = !empty($value) ? $value : "No Value";
$data['raw'] = $raw;
$data = array(
'voteNr' => 'My title' ,
'voteValue' => 'My Name' ,
'imgId' => $value,
);
#$this->db->insert('test_vote', $data);
$this->db->select('*');
$query = $this->db->get('test_vote',1);
$data['value'] = $query->result_array();
#Body View
$data['body'] = $this->load->view('dev/test',$data,true);
#Template == Never Change ==
$this->load->vars($data);
$this->load->view('inc/templates/dev', $data);
}
} #END All
?>
Code:
[removed]
$(document).ready(function(){
$('.dot').click(function(){
$(this).parent().click(function(e){ e.preventDefault();});
if($(this).attr('src') == '/images/layout/accept.png') {
$(this).attr('src', '/images/layout/cancel.png');
var value = 0;
$.ajax({
type: "POST",
url: "/dev/update/",
data: 'value=' + value, // get all the form field values
success: function(msg){
alert( "Data Saved: " + msg );
}
});
$.post("/dev/update/", { value: + value, time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
} else {
$(this).attr('src', '/images/layout/accept.png');
var value = 1;
$.ajax({
type: "POST",
url: "/dev/update/",
data: 'value: ' + value, // get all the form field values
success: function(msg){
alert( "Data Saved: " + msg );
}
});
$.post("/dev/update/", { value: + value, time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
}
//alert('calling: ' + $(this).parent().attr('href'));
//alert('value: ' + value);
});
});
[removed]
<div id="status"></div>
<div id="container">
<a href="<?=base_url();?>dev/update/"><img src="/images/layout/accept.png" class="dot"></a>
<a href="/dev/update/"><img src="/images/layout/cancel.png" class="dot"></a>
<a href="/dev/update/"><img src="/images/layout/cancel.png" class="dot"></a>
<a href="/dev/update/"><img src="/images/layout/accept.png" class="dot"></a>
<a href="/dev/update/"><img src="/images/layout/accept.png" class="dot"></a>
</div>
Why is it not getting the value that was sent via ajax?
Thank you All and especially At the Gates