' undefined不是一个功能' jQuery的

时间:2014-05-29 12:53:35

标签: jquery python

使用google appengine我尝试使用函数GDownloadUrl from here从过时的ajaxLoad()重现结果。但是我收到错误消息' Uncaught TypeError:undefined不是函数'显然关于名为readData的var或函数(我不确定它是什么)。

function ajaxLoad(url,callback,postData,plain) {
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType && plain) {
            http_request.overrideMimeType('text/plain');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange =  function() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                eval(callback(http_request));
            }
            else {
                alert('Request Failed: ' + http_request.status);
            }
        }
    };
if (postData) { // POST
    http_request.open('POST', url, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
    http_request.setRequestHeader("Content-length", postData.length);
    http_request.send(postData);
}
else {
    http_request.open('GET', url, true);
    http_request.send(null);
}

}

我使用ajaxLoad读取现有数据的调用如下。

ajaxLoad("details.txt?place={{place}}",readData);

readData定义如下。

  // === Define the function thats going to read the stored data ===
  readData = function(doc) {
    // === split the document into lines ===
    lines = doc.split("\n");
    for (var i=0; i<lines.length; i++) {
      if (lines[i].length > 1) {
        // === split each line into parts separated by Tab and use the contents ===
        parts = lines[i].split(String.fromCharCode(9));
        var ID  = parts[0];
        var lat = parseFloat(parts[2]);
        var lng = parseFloat(parts[3]);
        var details = parts[4];
        var pincategory = parts[5];
        var label = parts[6];
        var point = new google.maps.LatLng(lat,lng);
        var pinage = parts[7];
        myArray[i] = new Array(lat,lng,details,point,ID,pincategory,label,pinage);
      }
    }
    // create the marker
    for (var j=0; j<myArray.length; j++) {
      var alat = myArray[j][0];
      var alng = myArray[j][1];
      var adetails = myArray[j][2];
      var apoint = myArray[j][3];
      var ID = myArray[j][4];
      var acolor = colors[myArray[j][5]];
      var alabel = myArray[j][6];
      var apinage = myArray[j][7];
      if(!isNaN(alat+alng)){
        var marker = createMarker(apoint,adetails,ID,acolor,alabel,apinage);
      }
    }
  }

我的python数据类定义如下。

class Pin(db.Model):
    date = db.DateTimeProperty(auto_now_add=True)
    lat = db.FloatProperty()
    lng = db.FloatProperty()
    name = db.StringProperty()
    cornerColor  = db.StringProperty(default='ffffff')
    height = db.IntegerProperty(default=32)
    label = db.StringProperty(default='')
    labelColor = db.StringProperty(default='000000')
    labelSize = db.IntegerProperty(default=2)
    primaryColor = db.StringProperty(default='ff0000')
    shadowColor = db.StringProperty(default='000000')
    shape = db.StringProperty(default='circle')
    strokeColor = db.StringProperty(default='000000')
    width = db.IntegerProperty(default=32)
    category = db.IntegerProperty(default=0)
    scategory = db.StringProperty()
    logindex = db.IntegerProperty(default=0)
    imageindex = db.IntegerProperty(default=0)
    deleteRequested = db.BooleanProperty(default=False)

如果需要更多信息,请询问。

请问如何阅读数据?

1 个答案:

答案 0 :(得分:0)

我无法在我的应用中使功能ajaxLoad()正常工作。不过by reading Pamela Fox's posts我使用的是downloadUrl()。关键的新代码如下。

<script type="text/javascript" src="util.js"></script>

回调函数readData在下面的命令中保持不变。

downloadUrl("details.txt?place={{place}}",readData);