「リーフレット」ポップアップからPostgreSQLのセルの値を更新したいとします。 私がやろうとしているのは、フォーム内の送信ボタンが押された後、javascript関数内で呼び出されたPHPスクリプトを介してフォームに入力された値をPostgreSQLに送るときにjavascript関数を実行することですデータベース。「リーフレット」ポップアップからPostgreSQLの値を更新する
これは私のポップアップ機能がそのフォームのように見えるものです。ここで
function onEachFeature(feature, layer) {
insertsearch = feature.properties.gid
popUpText = "<b>Name</b>: " + feature.properties.businessna +
"<br> <b>Address: </b>" + feature.properties.addresslin + ", " + feature.properties.addressl_1 +
"<br><b>Food hygiene rating</b> <span id=skala>(1-5)</span> : " + feature.properties.ratingvalu +
"<form id='formoid' action='javascript:insertdata();'><br>Rating (between 1 and 5): <input type='number' name='quantity' min='1' max='5'><input type='submit'></form>"
feature.properties.gid;
feature.properties.popupContent = popUpText;
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
};
は、私が使用するPHPスクリプトです:( insert.php )
<?php
header("Access-Control-Allow-Origin: *");
$conn_str = "host=localhost dbname=geoweb
user=user password=user";
$dbconn = pg_connect($conn_str)
or die('Could not connect: ' . pg_last_error());
//innumber is supposed to be the rating value given by the user in the HTML form
$innumber=;
//idnumber is supposed to be the GID of the point that is being rated
//GID is this variable in the HTML function (insertsearch = feature.properties.gid)
$idnumber=;
//norate is the NUMBER OF TIMES the place has been rated
$norate= pg_query($dbconn, "SELECT rate FROM rating WHERE gid=$idnumber");
//findnumber is getting THE RATING value that the place already has
$findnumber= pg_query($dbconn, "SELECT rateav FROM rating WHERE gid=$idnumber");
//newvalue adds the existing rating value to the users new rating
$newvalue= $innumber + $findnumber;
//adds on 1 (one) to the norate to update how many times the place has been rated
$newcount= $norate+1;
//the query is updating the new rating value of the place.
//It replaces the old rating value with the a new value
$query="UPDATE rating SET rateav=$newvalue, rate=$newcount WHERE gid=$idnumber";
$result = pg_query($dbconn, $query);
pg_freeresult($result);
pg_close($dbconn);
?>
私の問題は今、JavaScript関数を作成する方法を考え出すされています。私が理解するように、私は、のinsert.phpスクリプトを使ってデータを送るためにjquery $ postメソッドを使うべきです。 Howver、私はHTML形式(action = ...)でJS関数にパラメータを送るはずですか?もしそうなら、どうすればいいのですか? PHPスクリプトを使用して2つの値を送信しようとしています。これは、ポップアップ機能の変数と、ユーザーがフォームに指定したレーティング番号のinsertsearchです。
ありがとうございました!