AJAXでのJS

jsの中のAjaxのget请求的写法
VAR
XHR = 新しいXMLHttpRequestを(); xhr.open(' 取得'' http://rap2api.taobao.org/app/mock/229494/news?content= ' + inp.value) xhr.send(); xhr.onreadystatechange = 関数(){ 場合(xhr.readyState == 4 ){ // はconsole.log(xhr.responeText } }
ポスト要求でJS文言
のvar
XHR = 新新のXMLHttpRequest(); xhr.open(ポストhttp://192.168.1.5/archives/register.php 真の); // ポストの要求を追加しなければならない場合リクエストヘッダ xhr.setRequestHeader(" コンテンツタイプ"" ファイルアプリケーション/ x-www-form-urlencodedで" ); xhr.send(" のuserName = " + user.value + ' &パスワード、= ' + pass.value); xhr.onreadystatechange = 関数(){ IF(xhr.readyState == 4 ){ VAR OBJ = JSON.parse(xhr.responseText)。 console.log(obj.responseCode)。 もし(obj.responseCode == " 0 " ){ window.location.href = " denglu.html " } } }

 

 

おすすめ

転載: www.cnblogs.com/white55k/p/11839889.html