Ajax

General Chat, Comments
Post Reply
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

Ajax

Post by KaL »

ok i was wondering can i update image using ajax?

i tried and fail. but if i do strings only it works!:


Image with ajax:

Code: Select all

TableFooter();

function PartUpdate($a)
{
echo"<td><img height='128' width='128' src='{$webBaseDir}modules/tbs/images/$a.png'></td>";

 }

Ajax::RegisterFunction("PartUpdate","partToUpdate");

TableHeader("This part will be updated");
echo "<div id='partToUpdate'>";
echo"image will display here";
echo "</div>";
TableFooter();

ButtonArea();
Ajax::Button("Click Me","PartUpdate(3)");
EndButtonArea();

With Strings only:

Code: Select all

TableFooter();

function PartUpdate()
{
 echo "sucker!";
 
 }
Ajax::RegisterFunction("PartUpdate","partToUpdate");

TableHeader("This part will be updated");
echo "<div id='partToUpdate'>";
echo"hi";
echo "</div>";
TableFooter();

ButtonArea();
Ajax::Button("Click Me","PartUpdate()");
EndButtonArea();



can anyone figure out how to do ajax with image?
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Ajax

Post by KyleMassacre »

Since it is using ajax/js/jquery or whatever your console log will let you know what your error is but I am going to go out on a whim here and say that it has to do with your string concatenation with your image directory. Also, I think your top "TableFooter()" is meant to be "TableHeader()"

Code: Select all

TableFooter();

function PartUpdate($a)
{
    echo "<td><img height='128' width='128' src='{$webBaseDir}modules/tbs/images/{$a}.png'></td>";//Notice the { and }
/* 
    or
    "<td><img height='128' width='128' src='".$webBaseDir."modules/tbs/images/".$a.".png'></td>";
*/
}

Ajax::RegisterFunction("PartUpdate","partToUpdate");

TableHeader("This part will be updated");
echo "<div id='partToUpdate'>";
echo"image will display here";
echo "</div>";
TableFooter();

ButtonArea();
Ajax::Button("Click Me","PartUpdate(3)");
EndButtonArea();
Post Reply

Return to “General”