Buddski Posted October 25, 2011 Share Posted October 25, 2011 You will need a "onreadystatechange" xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ // Do something here // } } The returned data will be contained in xmlhttp.responseText; Add this just before your xmlhttp.open() call. Link to comment https://forums.phpfreaks.com/topic/249770-running-a-database-insert-on-image-click/page/2/#findComment-1282075 Share on other sites More sharing options...
ukscotth Posted October 25, 2011 Author Share Posted October 25, 2011 Ok thanks so i can only get back one string ? can i not get back a set of variables ? Link to comment https://forums.phpfreaks.com/topic/249770-running-a-database-insert-on-image-click/page/2/#findComment-1282086 Share on other sites More sharing options...
Buddski Posted October 25, 2011 Share Posted October 25, 2011 You could send back JSON data but thats just a whole other can of worms. The best (quickest) would be for the vote.php to return the preformed HTML of the new image set (with all the onclick etc etc in it). Link to comment https://forums.phpfreaks.com/topic/249770-running-a-database-insert-on-image-click/page/2/#findComment-1282087 Share on other sites More sharing options...
ukscotth Posted October 25, 2011 Author Share Posted October 25, 2011 ok thanks, i have it working for one of the images, just need to get it working for the second image aswell. Is there a way I can split the responseText and then add each part to 2 seperate divs ? Link to comment https://forums.phpfreaks.com/topic/249770-running-a-database-insert-on-image-click/page/2/#findComment-1282096 Share on other sites More sharing options...
Buddski Posted October 25, 2011 Share Posted October 25, 2011 You could also split your responseText using a \n I guess. For example, your AJAX would return something like <img src="1.jpg"> <img src="2.jpg"> and then using javascript to split it.. var parts = xmlhttp.responseText.split("\n"); part[0] would contain <img src="1.jpg"> and part[1] would contain <img src="2.jpg"> Or..something (its 1:30 and I have to bee up in 6hrs for work so im a little scattered) The only other way would be to return a javascript object which you would more than likely have to eval() to make it usable. Link to comment https://forums.phpfreaks.com/topic/249770-running-a-database-insert-on-image-click/page/2/#findComment-1282106 Share on other sites More sharing options...
ukscotth Posted October 25, 2011 Author Share Posted October 25, 2011 Ok great thanks Link to comment https://forums.phpfreaks.com/topic/249770-running-a-database-insert-on-image-click/page/2/#findComment-1282109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.