basic usage of AJAX with php for Database update and retrieval

(Just a heads up, its a Lengthy question but im sure its very basic question for a ajax-php coder) Im trying to 'update db on some drag n drop event on one page' and 'reflect that change in other page without reload'. I have already written pretty much all the code, need your help in figuring out what is wrong. Here is the Html that I have written, First_html_file: Coconuts into Gunnybags
so there are 2 drag-able coconuts and there are 2 placeholders(place1 & place2). What I want to do is when the coconuts are dragged and placed on one of the placeholders, database's values should be updated. (say when a coconut is placed in 1st placeholder, place_id 1 - true, place_id 2 - false) For this, I'm making ajax call to a php file from JS's drop function like this.. JS_file: function drop(ev) { ev.preventDefault(); var data=ev.dataTransfer.getData("coconut");; var state = true; var id =; $.ajax({ url: "db_update.php", //calling db update file. type: "POST", data: { id: id, state: state }, //2 variables place_id and its state(True/False) cache: false, success: function (response) { //I dont know what to do on success. Can this be left blank like, success: ? $('#text').html(response); } }); } This is my db_update, db_update: On the receiving side I want to update the coconuts in the gunnybag without reloading the page, so I have written this ajax which uses db_fetch.php ajx.js file: window.onLoad = doAjax; function doAjax(){ $.ajax({ url: "db_fetch.php", dataType: "json", success: function(json){ var dataArray = JSON.decode(json); dataArray.each(function(entry){ var i=1; if(entry.valueName==true){ $q('place'+i).css( "display","block" ); } else{ $q('place'+i).css( "display","none" ); } i=i++; }) } }).complete(function(){ setTimeout(function(){doAjax();}, 10000); }); } here is the db_fetch.php: Finally my other page where this ajax is being called from. Second_html_file: Coconuts into Gunnybags //if i simply include the ajax script here will it be called //automatically? i want this script to keep up with the changes in db.
MAP: First_html_file->JS_file->db_update :: Second_html_file->ajx.js->db_fetch. Please point out what is wrong in this code, also respond to the //comments which are put along code. Your response is much appreciated. Thanks! #help me get this right# For ref I have hosted the files here, &

以上就是basic usage of AJAX with php for Database update and retrieval的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准