1

我正在处理一些代码,让用户在字段中输入邮政编码,如果它在用户单击发送时通过客户端验证,我希望脚本将邮政编码发送到地址并且后端开发人员已设置它up 以便它返回一个有效或无效的 json 文件。

问题是我现在得到的只是未定义的。

有人可以看到我做错了什么或提供一些建议或解决问题。我不太确定如何使用 console.log,这可能会对我有所帮助。谢谢。

jQuery.validator.addMethod("postalcode", function(postalcode, element) {
return this.optional(element) || postalcode.match(/(^\d{5}(-\d{4})?$)|   (^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
}, "Zip code not valid. Please try again.");

var myForm = $('#zipform');

myForm.validate({
  errorClass: "errormessage, intro-highlighted",
  onkeyup: false,
  highlight: function(element) {
        $(element).addClass('intro-highlighted');
    },
    unhighlight: function(element) {
        $(element).removeClass('intro-highlighted');
    },

  errorClass: 'error',
  validClass: 'valid',
  rules: {
    zipcode: { required: true, postalcode: true }
  },
  errorPlacement: function(error, element)
  {
    // Set positioning based on the elements position in the form
    var elem = $(element),
      corners = ['left center', 'right center'],
      flipIt = elem.parents('span.right').length > 0;

    // Check we have a valid error message
    if(!error.is(':empty')) {
      // Apply the tooltip only if it isn't valid
      elem.filter(':not(.valid)').qtip({
        overwrite: false,
        content: error,
        position: {
          my: 'top left',
          at: 'top left',
          target: $('#zipcode'),
          adjust: {
            y: -30
          }
        },

        show: {
          event: false,
          ready: true
        },
        hide: false,
      })

      // If we have a tooltip on this element already, just update its content
      .qtip('option', 'content.text', error);
    }

    // If the error is empty, remove the qTip
    else { elem.qtip('destroy'); }
  },
  success: $.noop, // Odd workaround for errorPlacement not firing!
})

$.ajax({
    url: "http://address/icantshow/json/checkZip.action?zipCode=" + zipcode + "?jsoncallback=?",
    type: "GET",
    async: false,
    dataType: "jsonp",
    /*data: {
        zipcode:$('#zipcode').val(),
        username: 'user',
        password: 'pass'
      },*/
    success: function(json) {
      console.log(typeof data);
      //console.log(jsondata);
       //$('.bar').css({display:'none'});
       //$('.loader').append(data);
    },
    error: function(e) {
      console.log(e.message);
    }
 })
4

1 回答 1

1
    //REPLACE
url: "http://address/icantshow/json/checkZip.action?zipCode=" + zipcode + "?jsoncallback=?",
//BY
    url: "http://address/icantshow/json/checkZip.action?zipCode=" + zipcode + "&jsoncallback=?",

//IN
success: function(json) {
      console.log(typeof data);
    },

//SHOULD BE
success: function(json) {
      console.log(json);
    },
于 2012-10-18T18:07:12.373 回答