我想发出一个简单的数据,如姓名,代码,日期...等我的数据库,我得到了使用JavaScript中的数据,并把它交给我的PHP文件使用Ajax,但没有任何反应,我不知道发生了什么,但Ajax什么都不做! 因此,请任何人查看代码,并告诉发生了什么事。 谢谢发送数据使用Ajax和PHP,但没有MySQL来发生
P.S.我的脚本在我的HTML文件的结尾处,就在结束标记之前。
<script type="text/javascript">
debugger;
window.onload = function() {
var platform = $("input:text[id=platform]").val();
var source = $("input:text[id=source]").val();
var code = $("input:text[id=code]").val();
var thedate = $("input:text[id=date]").val();
var payment_type = $("input:text[id=payment_type]").val();
var change_for = $("input:text[id=change_for]").val();
var order_comment = $("#order_comment").val();
var decline_reason = $("input:text[id=decline_reason]").val();
var order_reference_by_vendor = $("input:text[id=order_reference_by_vendor]").val();
var deliveryprovider_title = $("input:text[id=deliveryprovider_title]").val();
var social_reason = $("input:text[id=social_reason]").val();
var government_identification = $("input:text[id=government_identification]").val();
if(platform == ""){platform = "NULL"}
if(source == ""){source = "NULL"}
if(code == ""){code = "NULL"}
if(thedate == ""){thedate = "NULL"}
if(payment_type == ""){payment_type = "NULL"}
if(change_for == ""){change_for = "NULL"}
if(order_comment == ""){order_comment = "NULL"}
if(decline_reason == ""){decline_reason = "NULL"}
if(order_reference_by_vendor == ""){order_reference_by_vendor = "NULL"}
if(deliveryprovider_title == ""){deliveryprovider_title = "NULL"}
if(social_reason == ""){social_reason = "NULL"}
if(government_identification == ""){government_identification = "NULL"}
alert ("before ajax");
$.ajax({
type:"post",
url:"savedata.php",
data:{"platform": platform,
"source": source,
"code": code,
"thedate": thedate,
"payment_type": payment_type,
"change_for": change_for,
"order_comment": order_comment,
"decline_reason": decline_reason,
"order_reference_by_vendor": order_reference_by_vendor,
"deliveryprovider_title": deliveryprovider_title,
"social_reason": social_reason,
"government_identification": government_identification},
success: function(msg){
alert("Success Insert data");
}
});
alert ("after ajax");
}
</script>
和这里的PHP代码
<?php
function db_connect()
{
\t $servername = "localhost";
\t $username = "root";
\t $password = "";
\t $dbname = "integrationdb";
@mysql_connect($servername,$username,$password) or die ("error in host connection");
@mysql_select_db($dbname) or die("error in db connection");
}
db_connect();
$platform = $_POST['platform'];
$source = $_POST['source'];
$code = $_POST['code'];
$thedate = $_POST['thedate'];
$payment_type = $_POST['payment_type'];
$change_for = $_POST['change_for'];
$order_comment = $_POST['order_comment'];
$decline_reason = $_POST['decline_reason'];
$order_reference_by_vendor = $_POST['order_reference_by_vendor'];
$deliveryprovider_title = $_POST['deliveryprovider_title'];
$social_reason = $_POST['social_reason'];
$government_identification = $_POST['government_identification'];
$qry = "INSERT INTO orderinformation VALUES ('$platform','$source','$code','$thedate','$payment_type','$change_for','$order_comment','$decline_reason','$order_reference_by_vendor','$deliveryprovider_title','$social_reason','$government_identification')";
$result=mysql_query($qry);
if(isset($result)) {
echo "YES";
} else {
echo "NO";
}
?>
- 编辑 原谅我,如果我要问... ...它在JSON做区别,如果我使用('),而不是(“)??!
你看到这个警示(“成功插入数据”响应数据);正在显示? –
你是否在控制台中发现任何错误? –
请参阅https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php并停止使用这些MySQL的funtions插件PHP。 – BenRoob