0

I'm sending the json object userInfoRedCourses to my sendy database via the post method. This json object is sent from the previous page contains user details like email, name, address etc..If the user ticks the box the data is sent. I'm also changing some of the values in the object before the data is sent.

This works fine on desktop, but doesn't work at all on mobile. Please can anyone explain why?

I thought it might be a CORS error, but when I added dataType: 'jsonp',I stopped getting the CORS error, however the data is still not sent when using a mobile device. I see no other errors.

var userInfoRedCourses = <%- JSON.stringify(userInfo) %>;

  var redCourseTickYes = document.getElementById("redcoursetickyes");
              var redLicence = $("#Redlicence").val();
              var drivingBan = $("#drivingBan").val();
              var penPoints = $("#penaltyPoints").val();


              userInfoRedCourses.redcoursetickyes = $("#redcoursetickyes").val();
              userInfoRedCourses.Redlicence = redLicence;
              userInfoRedCourses.DrivingBan = drivingBan;
              userInfoRedCourses.penaltyPoints = penPoints;

  if(redCourseTickYes.checked){

            var redCourses = {
                 method: "POST",
                  "data": userInfoRedCourses,
                  crossDomain: true,
                  url: "https://example.com/sendy/subscribe",
                  dataType: 'jsonp',
                  "headers": {

                    "Host": "example.com",
                    "Accept-Encoding": "gzip, deflate",
                    "Connection": "keep-alive",
                  }
                };

                $.ajax(redCourses).done(function (response) {
                  console.log(JSON.stringify(response));
                });



              }
ASalmon
  • 15
  • 4
  • please add --- error: function (request, status, error) { alert(request.responseText); } --- to your ajax request and get what is eror – Harsimranjit Singh Mar 03 '20 at 12:39
  • how should I insert this into the ajax request? I've tried a few ways but the syntax doesn't seem correct. $.ajax(redCourses).done(function (response) { console.log(JSON.stringify(response)); error: function (request, status, error) { alert(request.responseText); }}); – ASalmon Mar 03 '20 at 12:57
  • why you can not insert brother ?? insert it to your json redCourses veriable – Harsimranjit Singh Mar 03 '20 at 13:09

0 Answers0