0

我是 Jquery 和 Parse 的新手,而且我不会说英语,所以首先对问题的语法感到抱歉。我写了一个函数来更新我在 parse.com 上的 Artist 对象 (updateArtist(objectId))。当我单击“保存”按钮时会调用此函数,并且在 FireFox 和 chrome 上运行良好,但在 Safari 上运行良好。

function updateArtist(objectId) {

  Parse.initialize("myid", "myid");


  alert(objectId);

  var Artist = Parse.Object.extend("Artist");
  var query = new Parse.Query(Artist);

  query.equalTo("objectId", objectId);

  query.first({
    success: function(object) {
      // Successfully retrieved the object.
      $('#createArtist').css('visibility', 'hidden');
      $('.loadingImage').css('visibility', 'visible');

      alert('success');

      var name = $("#txtName").val();
      var link = $("#txtLink").val();
      var desc = $("#txtDesc").val();
      var place = $("#txtPlace").val();
      var latitude = parseFloat($("#txtLat").val());
      var longitude = parseFloat($("#txtLong").val());
      var eventDate = $('#txtDate').val();
      var eventTime = $('#txtTime').val();

      console.log(eventDate);
      console.log(eventTime);
      console.log(name);
      console.log(link);
      console.log(place);
      console.log(desc);
      console.log(latitude);
      console.log(longitude);

      if (eventDate.charAt(2)=='/') {

          var dateArray = eventDate.split('/');

          var month = dateArray[0] - 1; 
          var day = dateArray[1];
          var year = dateArray[2];

        } else if (eventDate.charAt(2)=='-') {

          var dateArray = eventDate.split('-');

          var month = dateArray[1] - 1; 
          var day = dateArray[0];
          var year = dateArray[2];

        }

      console.log(month);
      console.log(day);
      console.log(year);
      var timeArray = eventTime.split(':');
      var finalDate = new Date(year, month, day, timeArray[0], timeArray[1], 0, 0); 

      console.log(timeArray);
      console.log(finalDate);


      var point = new Parse.GeoPoint(latitude, longitude);

      console.log(point);


      var fileUploadControl = $("#profilePhotoFileUpload")[0];

      if (fileUploadControl.files.length > 0) {
        var file = fileUploadControl.files[0];
        var photoName = "photo.jpg";

        var parseFile = new Parse.File(photoName, file);
      }

      parseFile.save().then(function(){

        object.save(null, {
          success: function (contact) {


            alert('secondo success');

            contact.set("name", name);
            contact.set("link", link);
            contact.set("description", desc);
            contact.set("place", place);
            contact.set("geoLocation", point);
            contact.set("eventDate", finalDate);

            contact.set("image", parseFile);

            contact.save();
            window.location.href = "artist_list.html";
          }
        });

      });



    },
    error: function(error) {
      alert("Error: " + error.code + " " + error.message);
    }


  });


}

我正在使用 Safari 6.0.5,警报和 console.log 给了我我想要的东西......我完全迷失了......

4

1 回答 1

0

当您调用“updateArtist”时?确保等待 $(document).ready(function(){…})。

于 2013-07-08T09:08:53.033 回答