我有这个代码:
我的观点:
<b><input type="text" id="pagibigno" onclick="window.location.assign('#')"/></b>
<div id="pagibig_form">
<div class="err" id="add_err"></div>
<form>
<label>Pagibig Number:</label>
<input type="text" id="signpagibigno" name="signpagibigno" value="signpagibigno" />
<input type="text" id="txtpagibigno" name="txtpagibigno" />
<input type="submit" id="login" value="Login" />
<input type="button" id="cancel_hide" value="Cancel" />
</form>
</div>
addField.php
<?php
include 'dbconn.php';
$signpagibigno = $_GET['signpagibigno'];
$txtpagibigno = $_GET['txtpagibigno'];
echo "INSERT INTO `employer_profile` (`id`, `pagibig_no`, `buss_name`, `sss_no`, `div_code`, `address`, `zip_code`, `tin`, `contact_no`)
VALUES (NULL, '$txtpagibigno', NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
$sql = $conn->prepare("INSERT INTO `employer_profile` (`id`, `pagibig_no`, `buss_name`, `sss_no`, `div_code`, `address`, `zip_code`, `tin`, `contact_no`)
VALUES (NULL, '$txtpagibigno', NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
// mysql_query($sql);
$sql->execute();
?>
popup.js
$(document).ready(function ()
{
$("#pagibigno").click(function ()
{
$("#shadow").fadeIn("normal");
$("#pagibig_form").fadeIn("normal");
$("#user_name").focus();
});
$("#cancel_hide").click(function ()
{
$("#pagibig_form").fadeOut("normal");
$("#shadow").fadeOut();
});
$("#login").click(function ()
{
pagibigno = $("#txtpagibigno").val();
$.ajax(
{
type: "GET",
url: "addField.php",
data: data,
success: function (html)
{
if (pagibigno != '')
{
$("#pagibig_form").fadeOut("normal");
$("#shadow").fadeOut();
}
else
{
$("#add_err").html("Please complete the field");
}
},
beforeSend: function ()
{
$("#add_err").html("Loading...")
}
});
return false;
});
});
当我运行 dataField.php 时,数据保存到我的数据库中。但是当我使用ajax发生的 View 时,数据没有保存。 我阅读了此代码的链接 Alert in Jquery pagination 请帮忙。谢谢
最佳答案
您没有将数据传递到 php 页面。请参阅下面的 jquery 代码:
$(document).ready(function () {
$("#pagibigno").click(function () {
$("#shadow").fadeIn("normal");
$("#pagibig_form").fadeIn("normal");
$("#user_name").focus();
});
$("#cancel_hide").click(function () {
$("#pagibig_form").fadeOut("normal");
$("#shadow").fadeOut();
});
$("#login").click(function () {
txtpagibigno = $("#txtpagibigno").val();//Getting value from text field
signpagibigno = $("#signpagibigno").val();//Getting value from text field
$.ajax({
type: "GET",
url: "addField.php",
data: "txtpagibigno="+txtpagibigno+"&signpagibigno="+signpagibigno,//Passing the values to the php page
success: function (html) {
if (pagibigno != '') {
$("#pagibig_form").fadeOut("normal");
$("#shadow").fadeOut();
} else {
$("#add_err").html("Please complete the field");
}
},
beforeSend: function () {
$("#add_err").html("Loading...")
}
});
return false;
});
});
关于javascript - jQuery-Ajax : insert data from php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20278556/