AJax¼¼Êõ

ÉîÈëÀí½âajaxϵÁеÚËÄƪ£ºÇëÇóʵÀý(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-03-09 10:02 ÎÒÒªÆÀÂÛ( )

ÏÂÃæÒÔÒ»¸öʵÀýÀ´ËµÃ÷GETºÍPOSTÁ½ÖÖÇëÇó·½Ê½µÄÓ¦Óà == body { font-size : 30px ; margin : 0 ; line-height : 1.5 ;} select , button , input { font-size : 30px ; line-height : 1.5 ;} === Ô±¹¤´´½¨== = === =

ÏÂÃæÒÔÒ»¸öʵÀýÀ´ËµÃ÷GETºÍPOSTÁ½ÖÖÇëÇó·½Ê½µÄÓ¦ÓÃ

==> body{font-size: 30px;margin: 0;line-height: 1.5;} select,button,input{font-size: 30px;line-height: 1.5;} > ===>Ô±¹¤´´½¨==> => ===> => ==> oSearch = document.getElementById('search'); (url,name,value){ url += (url.indexOf("?") == -1 ? "?" : "&"); url +=encodeURIComponent(name) + "=" + encodeURIComponent(value); return url; } oSearch.onclick = function(){ //´´½¨xhr¶ÔÏó var xhr; if(window.XMLHttpRequest){ xhr = new XMLHttpRequest(); }else{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); } //Òì²½½ÓÊÜÏìÓ¦ xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if(xhr.status == 200){ //ʵ¼Ê²Ù×÷ document.getElementById('searchResult').innerHTML = xhr.responseText; }else{ alert('·¢Éú´íÎó£º' + xhr.status); } } } //·¢ËÍÇëÇó var url = 'service.php'; url = addURLParam(url,'number',document.getElementById('keyword').value); xhr.open('get',url,true); xhr.send(); } oSave = document.getElementById('save'); (form){ var parts = [],field = null,i,len,j,optLen,option,optValue; for (i=0, len=form.elements.length; i < len; i++){ field = form.elements[i]; switch(field.type){ case "select-one": case "select-multiple": if (field.name.length){ for (j=0, optLen = field.options.length; j < optLen; j++){ option = field.options[j]; if (option.selected){ optValue = ""; if (option.hasAttribute){ optValue = (option.hasAttribute("value") ? option.value : option.text); } else { optValue = (option.attributes["value"].specified ? option.value : option.text); } parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(optValue)); } } } break; : : : : //custom button break; : //checkbox if (!field.checked){ break; } /* falls through */ default: //don't include form fields without names if (field.name.length){ parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value)); } } } return parts.join("&"); } oSave.onclick = function(){ //´´½¨xhr¶ÔÏó var xhr; if(window.XMLHttpRequest){ xhr = new XMLHttpRequest(); }else{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); } //Òì²½½ÓÊÜÏìÓ¦ xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if(xhr.status == 200){ //ʵ¼Ê²Ù×÷ document.getElementById('createResult').innerHTML = xhr.responseText; }else{ alert('·¢Éú´íÎó£º' + xhr.status); } } } //·¢ËÍÇëÇó xhr.open('post','service.php',true); xhr.setRequestHeader("content-type","application/x-www-form-urlencoded"); xhr.send(serialize(document.getElementById('postForm'))); } > { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } //ÉèÖÃÒ³ÃæÄÚÈݵÄhtml±àÂë¸ñʽÊÇutf-8£¬ÄÚÈÝÊÇ´¿Îı¾ header("Content-Type:text/plain;charset=utf-8"); $staff = array( array("name"=>"ºéÆß","number"=>"101","sex"=>"ÄÐ","job"=>'×ܾ­Àí'), array("name"=>"¹ù¾¸","number"=>"102","sex"=>"ÄÐ","job"=>'¿ª·¢¹¤³Ìʦ'), array("name"=>"»ÆÈØ","number"=>"103","sex"=>"Å®","job"=>'²úÆ·¾­Àí') ); ($_SERVER["REQUEST_METHOD"] == "GET"){ search(); }else if($_SERVER["REQUEST_METHOD"] == "POST"){ create(); } { (!isset($_GET['number']) || empty($_GET['number'])){ echo '²ÎÊý´íÎó'; return; } global $staff; $number = test_input($_GET['number']); $result = 'ûÓÐÕÒµ½Ô±¹¤'; //±éÀú$staff¶àάÊý×飬²éÕÒkeyֵΪnumberµÄÔ±¹¤ÊÇ·ñ´æÔÚ¡£Èç¹û´æÔÚ£¬ÔòÐ޸ķµ»Ø½á¹û foreach($staff as $value){ if($value['number'] == $number){ $result = "ÕÒµ½Ô±¹¤£ºÔ±¹¤±àºÅΪ" .$value['number'] ."£¬Ô±¹¤ÐÕÃûΪ" .$value['name'] ."£¬Ô±¹¤ÐÔ±ðΪ" .$value['sex'] ."£¬Ô±¹¤Ö°Î»Îª" .$value['job']; break; } } echo $result; } { //ÅжÏÐÅÏ¢ÊÇ·ñÌîдÍêÈ« if(!isset($_POST['name']) || empty($_POST['name']) || !isset($_POST['number']) || empty($_POST['number']) || !isset($_POST['sex']) || empty($_POST['sex']) || !isset($_POST['job']) || empty($_POST['job']) ){ echo "²ÎÊý´íÎó£¬Ô±¹¤ÐÅÏ¢Ìîд²»È«"; return; } echo "Ô±¹¤" .test_input($_POST['name']) ."ÐÅÏ¢±£´æ³É¹¦!"; } ?>

·ÖÏí¸øС»ï°éÃÇ£º

±¾ÎıêÇ©£º ajax/">ajax

Ïà¹ØÎÄÕÂ

·¢±íÆÀÂÛÔ¸ÄúµÄÿ¾äÆÀÂÛ£¬¶¼Äܸø´ó¼ÒµÄÉú»îÌíÉ«²Ê£¬´øÀ´¹²Ãù£¬´øÀ´Ë¼Ë÷£¬´øÀ´¿ìÀÖ¡£

  • ±¾Àà×îÈÈÐÂÎÅ

  • ¡¡

    1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

    Ïà¹ØÎÄÕÂ
    • php ajaxÎÞË¢ÐÂÉÏ´«Í¼Æ¬ÊµÀý´úÂë

      php ajaxÎÞË¢ÐÂÉÏ´«Í¼Æ¬ÊµÀý´úÂë

      2017-03-09 11:00

    • vueµÄajax²å¼þresourceÓ¦ÓÃ2

      vueµÄajax²å¼þresourceÓ¦ÓÃ2

      2017-03-09 09:08

    • Ajax´«Êä¶ÔÏ󣬼¯ºÏ»òÊý×é¡£

      Ajax´«Êä¶ÔÏ󣬼¯ºÏ»òÊý×é¡£

      2017-03-08 14:00

    • ajaxUpload.js 25ѧÌÃ

      ajaxUpload.js 25ѧÌÃ

      2017-03-08 10:02

    ÍøÓѵãÆÀ
    Ì