weixin_33724059 2013-07-28 16:43 采纳率: 0%
浏览 21

无法使我的JS代码正常工作

My JS and HTML is at a JS Fiddle, here. I've put the JSON object in the place for CSS because I don't have any css so I don't think it will cause a problem. The problem is that I can't get it working... I think I have a error somewhere in my ajaxCall function but I can't find it. The error message says

GET ....[HTTP/1.1 304 Not Modified 12ms]

I am trying at this on my local webserver, using Wamp.

JSON file:

{

"adrBook": [

  {
  "name": "Nikola Markovic",
  "email": "nikola@gmail.com",
  "location": "Serbia"
  },
  {
  "name": "Petar Nikolic",
  "email": "petar@gmail.com",
  "location": "Germany"
  }
  {
  "name": "Marko Stojanovic",
  "email": "markos@gmail.com",
  "location": "Swedish"
  },
  {
  "name": "Dusan Uzelac",
  "email": "dusanu@gmail.com",
  "location": "Holand"
  },
  {
  "name": "Petar Grujic",
  "email": "petarg@gmail.com",
  "location": "USA"
  },
  {
  "name": "Nikola Jesic",
  "email": "nikolaj@gmail.com",
  "location": "China"
  },
  {
  "name": "John Man",
  "email": "johnm@gmail.com",
  "location": "Japan"
  },
  {
  "name": "Jeniffer Gray",
  "email": "jenifferg@gmail.com",
  "location": "Bosnia"
  },
  {
  "name": "Marc Brown",
  "email": "marcb@gmail.com",
  "location": "Croatia"
  },
  {
  "name": "Nikola Ilic",
  "email": "nikolai@gmail.com",
  "location": "Macedonia"
  },
  {
  "name": "Nemanja Nikolic",
  "email": "nemanjan@gmail.com",
  "location": "Slovenia"
  },
  {
  "name": "Stefan Nikolic",
  "email": "stefann@gmail.com",
  "location": "Romania"
  }
  ]
  }
  • 写回答

1条回答 默认 最新

  • weixin_33721427 2013-07-28 17:20
    关注

    The problem lies within the browsers' default behavior when clicking on a <button> inside of a <form>. By default, this causes the form to be submitted, which results in a page reload. Thus, execution of your JavaScript code is halted and the XMLHttpRequest is never completed (or, maybe, even started).

    You can prevent the browser from reloading the page by calling the preventDefault() method of the event object:

    search: function(event) {
        event.preventDefault();
        // everything else stays the same …
    

    With this change, the rest of your code runs through, and you'll be confronted with the JSON syntax error(s) pointed out in the comments. Happy debugging! :)

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?