程序设计

专业和发烧友程序员的问答

30
JavaScript发布请求,例如表单提交
我正在尝试将浏览器定向到其他页面。如果我想要GET请求,我可能会说 document.location.href = 'http://example.com/q=a'; 但是,除非使用POST请求,否则我尝试访问的资源将无法正确响应。如果不是动态生成的,我可能会使用HTML <form action="http://example.com/" method="POST"> <input type="hidden" name="q" value="a"> </form> 然后,我只需从DOM提交表单。 但是我真的很想让我说的JavaScript代码 post_to_url('http://example.com/', {'q':'a'}); 最好的跨浏览器实现是什么? 编辑 对不起,我不清楚。我需要一个更改浏览器位置的解决方案,就像提交表单一样。如果XMLHttpRequest可以做到这一点,那不是很明显。而且这不应该是异步的,也不应该使用XML,因此Ajax并不是答案。
1529 javascript  http  post  submit  forms 




30
如何从文件内容创建Java字符串?
我已经在下面使用过一段时间了。至少在我访问过的网站上,它似乎是分布最广的。 在Java中,是否有更好/不同的方式将文件读取为字符串? private String readFile(String file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader (file)); String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); try { while((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); } return stringBuilder.toString(); } finally { reader.close(); } }
1512 java  string  file  file-io  io 

14
类型检查:typeof,GetType还是?
我见过很多人使用以下代码: Type t = typeof(obj1); if (t == typeof(int)) // Some code here 但我知道您也可以这样做: if (obj1.GetType() == typeof(int)) // Some code here 或这个: if (obj1 is int) // Some code here 就个人而言,我觉得最后一个是最干净的,但是我缺少什么吗?哪一种是最佳使用方式,还是个人喜好?
1511 c#  types  typeof  gettype 



30
如何将具有历史记录的SVN存储库迁移到新的Git存储库?
我阅读了Git手册,常见问题解答,Git-SVN崩溃课程等,它们都对此进行了解释,但是在任何地方都找不到像以下这样的简单说明: SVN存储库位于: svn://myserver/path/to/svn/repos Git存储库位于: git://myserver/path/to/git/repos git-do-the-magic-svn-import-with-history \ svn://myserver/path/to/svn/repos \ git://myserver/path/to/git/repos 我不希望它那么简单,也不希望它是单个命令。但我确实希望它不会尝试解释任何内容-仅说明在此示例中应采取的步骤。

30
.gitignore被Git忽略
我的.gitignore文件似乎被Git忽略了- .gitignore文件是否可能损坏?Git需要哪种文件格式,语言环境或文化? 我的.gitignore: # This is a comment debug.log nbproject/ 来自的输出git status: # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # debug.log # nbproject/ nothing added to …
1508 git  gitignore 

30
如何在SQL SELECT中执行IF…THEN?
Наэтотвопросестьответына 堆栈溢出нарусском:КаквыглядитконструкцияIF ... THENвSQL SELECT? 如何IF...THEN在SQL SELECT陈述中执行? 例如: SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product


30
如何获取所有Git分支
我克隆了一个Git存储库,其中包含大约五个分支。但是,当我这样做时,git branch我只会看到其中之一: $ git branch * master 我知道可以git branch -a看到所有分支,但是如何在本地拉出所有分支,所以当git branch显示时,它显示以下内容? $ git branch * master * staging * etc...
1506 git  branch  git-branch 

5
尝试捕获加快我的代码?
我编写了一些代码来测试try-catch的影响,但是看到了一些令人惊讶的结果。 static void Main(string[] args) { Thread.CurrentThread.Priority = ThreadPriority.Highest; Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; long start = 0, stop = 0, elapsed = 0; double avg = 0.0; long temp = Fibo(1); for (int i = 1; i < 100000000; i++) { start = Stopwatch.GetTimestamp(); temp = Fibo(100); stop = Stopwatch.GetTimestamp(); elapsed …

18
如何通过索引从列表中删除元素
如何在Python中按索引从列表中删除元素? 我找到了list.remove方法,但是说我要删除最后一个元素,该怎么做?似乎默认的remove搜索列表,但是我不希望执行任何搜索。
1503 python  list 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.