Это код для генерации страницы:
<div id="mali_oglasi">
<?php foreach ($mgs as $key) : ?>
<p class="mali_oglas">
<span class="name"><?php echo $key['name'] ?></span>
<span class="body"><?php echo $key['body'] ?></span>
<span class="contact_author"><?php echo $key['contact_author'] ?></span>
<span class="date_created"><?php echo $key['date_created'] ?></span>
<span class="date_expires"><?php echo $key['date_expires'] ?></span>
<span class="email"><?php echo $key['email'] ?></span>
<?php foreach ($lokacija as $lok) : ?>
<?php if($lok['id_location'] == $key['location_id']) : ?>
<span class="lokacija" id="<?php echo $lok['id_location'] ?>"><?php echo $lok['name'] ?></span>
<?php endif ?>
<?php endforeach; ?>
<?php foreach ($kategorija as $kat) : ?>
<?php if($kat['id_category'] == $key['category_id']) : ?>
<span class="kategorija" id="<?php echo $kat['id_category'] ?>"><?php echo $kat['name'] ?></span>
<?php endif ?>
<?php endforeach; ?>
<a class="obrisi" id="<?php echo $key['id_global_info'] ?>">Obrisi</a>
<a class="izmeni" id="<?php echo $key['id_global_info'] ?>">Izmeni</a>
</p>
<?php endforeach; ?>
</div>
, который даст такой результат:
<div id="mali_oglasi">
<p class="mali_oglas">
<span class="name">fbsd</span>
<span class="body">sdhdsf</span>
<span class="contact_author">mirko</span>
<span class="date_created">2012-03-15 11:24:19</span>
<span class="date_expires">2012-04-14 11:24:19</span>
<span class="email">a@a.com</span>
<span class="lokacija" id="1">Pirot</span>
<span class="kategorija" id="1">Auto i Moto</span>
<a class="obrisi" id="19">Obrisi</a>
<a class="izmeni" id="19">Izmeni</a>
</p>
<p class="mali_oglas">
<span class="name">dsh</span>
<span class="body">dshg</span>
<span class="contact_author">mirko</span>
<span class="date_created">2012-03-15 11:17:52</span>
<span class="date_expires">2012-04-14 11:17:52</span>
<span class="email">a@a.com</span>
<span class="lokacija" id="1">Pirot</span>
<span class="kategorija" id="1">Auto i Moto</span>
<a class="obrisi" id="18">Obrisi</a>
<a class="izmeni" id="18">Izmeni</a>
</p>....
</div>
и JS для replaceWith
и load
:
$(parent).on('click', '.izmeni', function() {
var name = $(this).siblings('.name').text();
var body = $(this).siblings('.body').text();
var email = $(this).siblings('.email').text();
var contact_author = $(this).siblings('.contact_author').text();
var id_lok = $(this).siblings('.lokacija').attr("id");
var id_kat = $(this).siblings('.kategorija').attr("id");
$(this).siblings('.name').replaceWith('<input value="' + name + '" />');
$(this).siblings('.body').replaceWith('<textarea>' + body + '</textarea>');
$(this).siblings('.date_created').hide();
$(this).siblings('.date_expires').hide();
$(this).siblings('.email').replaceWith('<input value="' + contact_author + '" />');
$(this).siblings('.lokacija').replaceWith(function(){
$(this).load("<?php echo base_url() ?>form/location", {'id' : id_lok})
});
$(this).siblings('.kategorija').replaceWith(function(){
$(this).load("<?php echo base_url() ?>form/category", {'id' : id_kat})
});
});
load вызывает следующую страницу (для lokacija
):
<select>
<?php foreach ($lokacija as $lok) : ?>
<option
<?php if($lok['id_location'] == $id) : ?>
selected="selected"
<?php endif ?>>
<?php echo $lok['name'] ?>
</option>
<?php endforeach; ?>
</select>
Все, кроме lokacija и kategorija, заменено, но в firebug я получаю положительный ответ (запрошенная страница загружается безошибки но это не отображается).Что я делаю не так?