高手們,請問怎樣使用ajax pass 這兩個value?

高手們,請問怎樣使用ajax pass 這兩個value給php?

當使者按了#e50648時及選擇了quantity的option value "1"時,便會把#e50648及1 傳送給php

如此類推
<li id="#0a0000" class="selectcolor selected"></li>
<li id="#e50648" class="selectcolor "> </li>
<li id="#b5b3b3" class="selectcolor "> </li>

<select name="quantity">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
</select>

標籤:

評論

  • 什麼都沒有
    $(document).ready(function() {
    	$('.selectcolor').click(function () {
    			var color = $(this).attr('id');
    			var size = $('#size').val();
    			$('#selectedcolor').val(color);
    			//alert(size);
    			
    			if (color == "" || size == "") {
    				document.getElementById("txtHint").innerHTML = "";
    				return;
    			} else { 
    				if (window.XMLHttpRequest) {
    					// code for IE7+, Firefox, Chrome, Opera, Safari
    					xmlhttp = new XMLHttpRequest();
    				} else {
    					// code for IE6, IE5
    					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    				}
    				xmlhttp.onreadystatechange = function() {
    					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    						document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
    					}
    				}
    				xmlhttp.open("GET","getitem.php?color="+color+'&size='+size,true);
    				xmlhttp.send();
    			}		
    			
    	});
    });
    
    


    php
    <?
    echo $_GET['color'];
    echo $_GET['size'];
    ?>
    
  • 解決了
    $(document).ready(function() {
    	$('.selectcolor').click(function () {
    			var color = $(this).attr('id');
    			var size = $('#size').val();
    			$('#selectedcolor').val(color);
    			//alert(size);
    			
    			
    			$.ajax({
    				type: 'POST',
    				// make sure you respect the same origin policy with this url:
    				// http://en.wikipedia.org/wiki/Same_origin_policy
    				url: 'getitem.php',
    				data: { 
    					'color': color, 
    					'size': size 
    				},
    				success: function(msg){
    					alert(msg);
    				}
    			});		
    			
    	});
    });
    
Sign In or Register to comment.