简体   繁体   English

使用Ajax和PHP将数据发送到MySQL,但没有任何反应

[英]Sending data to MySQL using Ajax and PHP but nothing happens

I want to send a simple data, like name, code, date... etc to my Database, I got the data using JavaScript, and sent it to my PHP file using Ajax, but nothing happens and I don't know what's happening, but Ajax do nothing!! 我想将一个简单的数据(例如名称,代码,日期等)发送到我的数据库,我使用JavaScript获取了数据,然后使用Ajax将其发送到了我的PHP文件,但是什么也没发生,我也不知道发生了什么但是Ajax什么也没做! So, please can anyone review the code, and tell what's going on.. thanks 所以,请任何人都可以查看代码,并告诉发生了什么..谢谢

PS my script in the END of my HTML file, right before the ending tag. 在结束标签之前,将我的脚本放在HTML文件的END中。

 <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> 

and here's the PHP code 这是PHP代码

 <?php function db_connect() { $servername = "localhost"; $username = "root"; $password = ""; $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"; } ?> 

  • EDIT Excuse me if I'm asking... will it do difference if I use ( ' ) instead of ( " ) in JSON??! 编辑对不起,如果我问...如果在JSON中使用(')而不是(“),会有所不同吗?

尝试通过chrome工具栏查看网络,它可以帮助您跟踪请求,读取其标头并检查可能包含错误消息的响应数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM