我有这个代码,当点击保存按钮时,它会保存包含vectorOutput和vectorName的数据。基于保存功能,我想编写一个函数,在单击按钮加载时加载这些数据。有人能帮助我吗?
jQuery(document).ready(function(){
/*if the submit Button gets clicked this function is called*/
jQuery("#submitButton").click(function() {
/*the text of the html field output and vectorName are stored into javascript variables vectorOutput & VectorName*/
var vectorOutput = jQuery("#output").val();
var vectorName = jQuery("#vectorName").val();
/*the jQuery.ajax gets openend*/
jQuery.ajax({
/*typ POST gets defined*/
type: "POST",
/*the PHP file that receives the POST*/
url: "parser22.php",
/*the data that gets transfered*/
data: {
/*vector: contains the geometric information of the overlay, in kml format*/
vector: vectorOutput,
/*name: contains the chosen name of the geofence*/
name: vectorName
},
success: function(html){ //so, if data is retrieved, store it in html
/*if the save button gets clicked the field with the geofencename */
jQuery("#output").val('');
/*and kml koordinates get emptied*/
jQuery("#vectorName").val('');
/*to show the user that it worked alert Window pops up*/
alert("Geofence successfully saved!");
}
}); //close jQuery.ajax(
});
});
答案 0 :(得分:1)
我给你一个指南,所以你可以学习:)
因此,假设parser22.php
文件收到POST
个vars,然后对您的数据库执行INSERT INTO
语句...
尝试执行相同操作,但在ajax调用中使用GET
作为type:
,并在数据库上执行SELECT
语句。
使用firebug(firefox)或开发人员工具(chrome)查看实际发送和接收的内容。
在ajax()
来电中使用此功能进行日志记录:
success function(html): {console.log(htm)},
error function(e) {console.log(e)}
在控制台中获取信息。 console.log是alert()
修改强>
/*the SELECT query gets created*/
$eintrag = "SELECT geofencename,geometry,fk_user_geofence FROM public.geofence";
/*the above mentioned query gets executed
--> this always executes a query, no matter what kind */
$eintragen = pg_query($eintrag);
另见W3schools有关SQL和查询数据库的简单介绍