开发者

Issues with Jquery .post and google chrome on a linux server

开发者 https://www.devze.com 2023-04-11 06:01 出处:网络
After doing test after test and creating new scripts I have discovered that chrome is having issues with this part of my jquery script:

After doing test after test and creating new scripts I have discovered that chrome is having issues with this part of my jquery script:

 $(document).ready(function(){

    $(".subto").click(function() {
    var data = {ramp: ramp, toilet:toilet, door:door, blind:blind,
    dog:dog, assist:assist, ear:ear, lift:lift, park:park, ramped:ramped, star:star
    };
     levelramp(data);
   });


function levelramp(ramp,toilet) {
    v开发者_运维问答ar url = "http://youraccessguru.com/sesstest1.php";
    $.post(url, {ramp: ramp},function(data) {
       $("#text").val(data).show();
    });

    }

http://youraccessguru.com/sesstest.php To get the error still depends on how long you take clicking the buttons try it to see. If you ASAP click a picture and submit the script itwill work but if you press back and wait 30 secs on page then select and click submit the hightlight would have not changed or worked.

The first button doesnt work anyway separate issue just leave unset.

The site works fine in any other browser except Google chrome


The first issue I see is that you're binding a POST request to a submit button that submits it's own form, and you're not preventing that form from being submitted. So your script does this when you click subto:

  1. Fire ajax post to http://youraccessguru.com/sesstest1.php
  2. Immediately after that fire regular POST request to http://youraccessguru.com/sesstest.php with no data

Note that these may not even happen in order. I have no idea what number 2 actually does, but my assumption is that it's redirecting you to sesspreview.php if it receives POST data.

So you have 2 choices. If you want to do a page refresh, there's absolutely no need for you to be using an ajax request. If you still want to use ajax, stop the regular form from being submitted, and redirect to sesspreview.php on the ajax complete function.

EG:

$(function(){
  $(".subto").click(function(e) {
    e.preventDefault();
    var data = {ramp: ramp, toilet:toilet, door:door, blind:blind, dog:dog, assist:assist, ear:ear, lift:lift, park:park, ramped:ramped, star:star};
    levelramp(data);
  });


  function levelramp(ramp,toilet) {
    var url = "http://youraccessguru.com/sesstest1.php";
    $.post(url, {ramp: ramp}, function(data) {
      window.location.href = "sesspreview.php";
    });
  }
});

Of course this depends on how your PHP files are set up and what they are actually doing. I have no idea, so if you're POSTing data to sesspreview.php, this won't work.

EDIT: Ok, so you continue using AJAX, then regular POST to submit the rest of the data. In this case, submit AJAX first, then wait for ajax response before submitting rest of the form. Give your form an ID, then use code like this:

$(function(){
  $(".subto").click(function(e) {
    e.preventDefault();
    var data = {ramp: ramp, toilet:toilet, door:door, blind:blind, dog:dog, assist:assist, ear:ear, lift:lift, park:park, ramped:ramped, star:star};
    levelramp(data);
  });


  function levelramp(ramp,toilet) {
    var url = "http://youraccessguru.com/sesstest1.php";
    $.post(url, {ramp: ramp}, function(data) {
      $('#formID').submit();
    });
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消