I had to ask this one again, sorry. so i am running this jquery to slide toggle a span in my php loops output. i have some php that generates some calls to the db to get more detailed information back for each item. i know so far i have got it making the call to the php script, i can see the packets returning with the html echoed from the php file. but im having difficulty getting jquery to insert the returned data into the specified span. this is a simplified version of what the loop items look like:
<span class="searchitem">
<span style="visibility:hidden;" class="name">some name</span>
<span class="btn">Details</span>
<span class="itemdetails" style="display: none;">
//hidden area to populate with returned ajax html from php script
</span>
</span>
<span class="searchitem">
<span style="visibility:hidden;" class="name">another name</span>
<span class="btn">Details</span>
<span class="itemdetails">
<div>
<p>
this is the area i need the html to populate
</p>
</div>
</span>
</span>.................
this is the jquery that im trying to run, i know everything works up to success i cant get the data from there
<script type="text/javascript">
var ajax_load = "<img src='images/loading.gif' style='width:50px;' alt='loading...' />";
var loadUrl = "ajax/item_details.php";
$(document).ready(function ()
{
$('.searchitem').each(function () {
var itemname = $(this).find('.name').text();
var ename = encodeURI(itemname);
var requestUrl = loadUrl + ename;
$(this).find('.itemdetails').hide();
$(this).find('.btn').click(function ()
{
var returned = "";
$.ajax({
type: "GET",
url: loadUrl,
data: "name=" + ename,
dataType: "text",
error: function () { alert("error") },
success: function (data) { $(".ptavail").append(data); alert("successful") }
});
$(this).parent().find('.ptavail').html(ajax_load).slideToggle(1500).html(returned);
});
});
});
</script>
as you can see from the code im trying to get the click function the set everything off. i know the php file is recieving the call and returning the data but im stuck trying to get the jquery to fill the .itemdetails with the returned data. what is wrong with this, would i need to put the ajax into a seperate function for it to behave like i need, or do i need to make it synchronous for it to work. im trying to basically replace everything between .itemdetails spans with first a loading symbol and then the data returned with ajax.... as it is now i get error alert so there's something wrong with the ajax call i know it does the request properly and the php returns the results but getting ajax to read them is proving problematic, i can see that the content type in the headers is text, so how do i get the ajax to do the call properly.