douluanji8752 2018-07-10 20:30
浏览 24

使用ajax从php文件中检索数据库密码

I have a js file that creates a form to collect clients contact info. When the form is submitted it sends a url string to the database. However the string needs to include a token and password to login to the database. So i need to somehow hide the token and password in a php file and add it to the string when the client hits submit. so far ive been able to get the data from a php file using .get or .ajax, but the js file already uses an .ajax request and i'm not sure how to combine them together. Any ideas? Thank you!

function initPopup() {
        // open on load
        if (xanadu_settings['show_popup'] == 'open') {
          openXanadu();
        }
        // open on mouse out
        else {
          $('html > body').mouseleave(function() {
            if (!popup_visible) {
              openXanadu();
            }
          });
        }
      }

      // This gets the login string i need to add to the form subit string below
      var dataString = 'login';

      $.ajax({
        type: 'GET',
        url: "login.php",
        data: {data : dataString}, 

        success: function(data) {
          returnedvalue = data;
          console.log(data);

        }

      });


      $("#xanadu_wrapper form").validate({

        rules: {
          name: "required",
          email: {
            required: true,
            email: true
          }
        },
        messages: {
          name: "Please specify your name",
          email: {
            required: "We need your email address to contact you",
            email: "Your email address must be valid"
          }
        },


        submitHandler: function(form, data) {
          var report_url = "http://myLinkToTheAPI";
          var submit_data = {
            // token: $(form).find('input.token').val(),
            // pass: $(form).find('input.pass').val(),
            campaignId: $(form).find('input.campaignId').val(),
            ipAddress: $(form).find('input#ipAddress').val(),
            source: $(form).find('input.source').val(),
            name: $(form).find('input.name').val(),
            email: $(form).find('input.email').val(),
            phone: $(form).find('input.phone').val(),

          }


          var form_submitted = false;
          var submit_data = $(form).serialize();


          $.ajax({
            type: 'GET',
            url: report_url,
            data: submit_data,

            complete: function() {
              if ( ($(form).attr('action') != '') && (form_submitted == false) ) {
                $(form)[0].submit();
                form_submitted = true;
              }
              $(form).find('input, button').attr('disabled', '');
              //Thank you! We will contact you shortly.
              $(form).after('<p class="success-alert">' + xanadu_settings['success_message'] + '</p>');
              $(form).next('.success-alert').fadeIn();
              console.log(form);
              console.log(form_submitted);

              if (xanadu_settings['prevent_after_submission'] == 'true') {
                setBlockCookie();
              }
            }
          });


          setTimeout(function(){
            if ( ($(form).attr('action') != '') && (form_submitted == false) ) {
              $(form)[0].submit();
              form_submitted = true;
            }
          }, 500);

        }

      });
  • 写回答

1条回答 默认 最新

  • duanjiao2978 2018-07-10 20:52
    关注

    Just do your updates / inserts in the AJAX call?

    When they hit submit, serializeArray() the form, pass your form data to the receiving page, and handle all database interaction on the server. You should never store database information on the client.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看