2011-10-27 103 views
1

我正在嘗試使WHOIS腳本能夠顯示域名的可用性。我已經完成了PHP。我所需要的只是jQuery部分,它可以檢測輸入內容的變化,向頁面發送POST請求並在特定div中顯示頁面內容。更改來自URL的輸入更改的div內容(WHOIS)

這裏是我的HTML

<div class="input"> 
    <input type="text" name="domain" placeholder="monsiteweb.com"/> 
</div> 
<div id="result"> 
</div> 

jQuery的我已經把現在(沒有工作)

<script> 
$(document).ready(function(){ 
    $("input[name=domain]").change(function() { 
     alert("Changed!"); 
}); 
</script> 

非常感謝

回答

2

基本上是:

$("input[name=domain]").change(function() { 
    $.post('script.php', { query: $(this).val() }, function(data) { 
      $('#result').html(data); 
    }); 
}); 

然後對用戶的輸入你的PHP腳本檢查$_POST['query']

+0

謝謝!完美的工作:)! – jpmonette

2

你缺少一個接近括號有:

<script> 
$(document).ready(function(){ 
    $("input[name=domain]").change(function() { 
     alert("Changed!"); 
    }); 
}); 
</script> 

另外,不要忘記,你離開現場後纔會得到警報。

+0

你沒有回答馬問題! – jpmonette

+0

你說得對。我看到了這個錯誤,你指出它不起作用,所以我簡單地糾正了它。 – samura

1

你已經開了一些支架,未關閉:

<script> 
$(document).ready(function(){ 
    $("input[name=domain]").change(function() { 
     alert("Changed!"); 
    }); 
}); 
</script>