英文:
Data reappears after a few seconds when "JSON Remove button" is pressed
问题
I'm currently in the process of creating a HTTP web service that will return data in JSON, XML and String formats. When entering a string and pressing "JSON Search" it will return data back from a database stored in Google SQL. However when I press the "JSON Remove" button next to the "JSON Search" button the data is cleared and then reappears after a few seconds. a br tag between the buttons seems to resolve the issue but messes around with the layout which I don't want to happen.
Code is within the linked image
英文:
I'm currently in the process of creating a HTTP web service that will return data in JSON, XML and String formats. When entering a string and pressing "JSON Search" it will return data back from a database stored in Google SQL. However when I press the "JSON Remove" button next to the "JSON Search" button the data is cleared and then reappears after a few seconds. a br tag between the buttons seems to resolve the issue but messes around with the layout which I don't want to happen.
Code is within the linked image
答案1
得分: 0
按钮的默认 type
是 "submit"。您已明确将您的 JSON 搜索按钮设置为提交按钮,但技术上您的删除按钮也是一个提交按钮。添加属性 type="reset"
可以将其设置为一个实际清除表单的按钮。或者如果您只想让它执行事件处理程序而不执行任何其他操作,可以使用 type="button"
。
目前的问题是,您可能有一个处理程序,当单击删除按钮时会清除数据,但由于它是一个(不经意的)提交按钮,它也会触发另一个查询。
英文:
The default type
of a <button>
is "submit". You have explicitly set your JSON Search button to be a submit button, but technically so is your Remove button. Add the attribute type="reset"
to have that one be a button that actually clears the form. Or type="button"
if you just don't want it to do anything except run your event handler.
The problem right now is that you probably have a handler that is clearing the data when you click the Remove button, but since it's an (unintended) submit button, it's also kicking off another query.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论