是否可以使用Javascript/Html5來檢查特定網頁的http回覆代碼?例如,如果用戶輸入一個句子,我想檢查一下,看看我是否有一個音頻文件用於每個單詞。我意識到我應該使用數據庫來查找單詞的可用性,但我目前正在進行一個非常簡單的演示,該演示目前由單個html文件和一組ogg文件組成。Html/Javascript中的HTTP響應代碼
0
A
回答
1
XHR的當前版本現在已經允許通過它們進行表單提交。我一直在使用這一段時間來做JavaScript RPC到MySql,它像一個冠軍。當然,XHR一直都有你想要的HTTP狀態碼。
只需範圍從當前文檔在Mozilla的網站XMLHTTP過,你就會有一個踢像你在任何時間
1
你可以嘗試使用AJAX實現這一希望。下面是使用jQuery AJAX功能一個簡單的例子:
// Assuming this is the word you are looking for
var str = "bells";
$.ajax("www.example.com/audio/" + str + ".ogg").done(function() {
// An audio file for that word exists
}).fail(function() {
// There is no audio file for that word
});
對於你可能只是把它分解成詞的整個句子和單獨看每一個。
1
XMLHttpRequest的肯定是要走的路,假設你不打算使用一個數據庫(我會強烈建議,因爲他們是完全真棒。)
function oggSearch() {
alert(this.responseText);
};
var sInput = ''; //grab it from whatever element you're using
var oggReq = new XMLHttpRequest();
oggReq.onload = oggSearch;
//I'm not sure if concatenating the file type will cause issue
oggReq.open("get", sInput + ".ogg", true);
oggReq.send();
我顯然還沒有測試上面,但它是基於下面的鏈接。
https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest
相關問題
- 1. JMeter HTTP響應代碼200
- 2. Google GCM中的HTTP響應代碼401
- 3. 驗證PHPUnit中的HTTP響應代碼
- 4. IE中的HTTP響應狀態代碼
- 5. Jmeter:響應代碼:非HTTP響應代碼:javax.net.ssl.SSLHandshakeException
- 6. 響應代碼:非HTTP響應代碼:org.apache.http.conn.HttpHostConnectException
- 7. 響應消息:非HTTP響應消息:無協議:響應代碼:非HTTP響應代碼:java.net.MalformedURLException
- 8. 在android中找出http響應代碼
- 9. 編程的Http響應代碼
- 10. Cohttp - 在不同的HTTP響應代碼
- 11. HttpPost GET HTTP響應代碼的Android
- 12. Google AdWords無效的HTTP響應代碼
- 13. 無效的HTTP響應代碼'0'
- 14. 「最佳嘗試」的HTTP響應代碼
- 15. HTTP響應代碼不同的2.7
- 16. 無效的HTTP響應代碼 '404'
- 17. HTTP響應代碼的Python例外
- 18. 得到一個錯誤「響應代碼:非HTTP響應代碼:org.apache.http.conn.HttpHostConnectException」在JMeter的
- 19. Django http響應代碼500錯誤
- 20. HTTP響應代碼:411 for Apache with ApacheOltu
- 21. 如何檢測http響應代碼?
- 22. 獲取HTTP響應代碼在MUnit
- 23. 更改Stripes HTTP響應代碼
- 24. 使用python獲取http響應代碼
- 25. Java HTTP響應代碼,URL,IOException
- 26. Retrofit/RxJava - 獲取http響應代碼
- 27. 執行代碼HTTP響應發送
- 28. 如何獲得http響應代碼
- 29. 從網址獲取http響應代碼
- 30. http響應代碼SSL網站asp
[XMLHttpRequest的](https://developer.mozilla.org/en/docs/DOM/XMLHttpRequest)(AJAX) – 2013-05-12 20:36:31