2017-12-08 21:37
浏览 174

使用PHP / AJAX将数据插入MySQL数据库,在插入后执行成功选项(回调)

I've been trying to make a simple site, and I can't quite wrap my head around some of the things said here, some of which are also unrelated to my situation.

The site has a form with 3 input boxes, a button, and a list. The info is submitted through a separate PHP file to a MySQL database, once the submit button is clicked. I'm supposed to make the list (it's inside a div) update once the info is successfully sent and updated in the database. So far I've made it work with async:false but I'm not supposed to, because of society.

Without this (bad) option, the list doesn't load after submitting the info, because (I assume) the method is executed past it, since it doesn't wait for it to finish.

What do I exactly have to do in "success:" to make it work? (Or, I've read something about .done() within the $.ajax clause, but I'm not sure how to make it work.)

What's the callback supposed to be like? I've never done it before and I can get really disoriented with the results here because each case is slightly different.

function save() {
    var name = document.getElementById('name');
    var email = document.getElementById('email');
    var telephone = document.getElementById('telephone');
        url: "save.php",
        method: "POST",
        data: { name: name.value, email: email.value, telephone: telephone.value },
        success: $("List").load(" List")

Thank you in advanced and if I need include further info don't hesitate to ask.


图片转代码服务由CSDN问答提供 功能建议

我一直在努力创建一个简单的网站,而我无法完全绕过一些网站 这里说的一些东西,其中一些也与我的情况无关。

该网站有一个包含3个输入框,一个按钮和一个列表的表单。 单击提交按钮后,信息将通过单独的PHP文件提交到MySQL数据库。 一旦信息在数据库中成功发送和更新,我应该将列表(它在div中)更新。 到目前为止,我已经使它与异步一起工作:假,但我不应该,因为社会。

如果没有这个(坏)选项,列表在提交信息后就不会加载,因为(我假设)该方法是在它之后执行的,因为它不等待它 完成。

在“成功:”中我应该做些什么才能使其发挥作用? (或者,我在$ .ajax子句中读到了关于.done()的内容,但我不确定如何使其工作。)

回调应该是什么样的? 我以前从来没有这样做过,因为每个案例都略有不同,我可能会对这里的结果感到迷失方向。

  function save(){
 var name = document.getElementById('name'); 
 var email = document.getElementById('email')  ; 
 var telephone = document.getElementById('telephone'); 
 $ .ajax({
方法:“POST  “,
 \  n}); 

谢谢你的高级和如果 我需要包含更多信息,请不要犹豫。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题