2011-02-17 76 views
1

終於讓我的域名檢查工作。現在的問題是我有一個表單(搜索域),當用戶鍵入並提交時,它將查詢傳遞到process.php並出: 回聲「$域是/不可用」Ajax和php問題

我想要的是在結果頁面上返回(結果頁面上還有一個搜索表單,因此如果有人在那裏搜索,它將顯示在同一頁面上)。在用戶點擊它時通過http://example.com/process.php?domain=domain.com(etc ...)。

我認爲我需要的是Ajax在去到process.php之前拉這個url,然後ajax運行查詢過程將結果發送回ajax並在結果頁面輸出。另外我有另一個PHP腳本,它顯示不同的域名,並顯示它們可用或不可用的ID。所以我也需要ajax來運行它並顯示。

我對ajax很新,但在尋找教程,但其中大部分都是在聯繫表單之後顯示成功消息等。如果有人能指出我正確的方向,很欣賞它。

編輯

這就是我,但資訊科技署還是重新引導我process.php

HTML

<form method="get" id="form"> 
    <input type="text" class="searchdomains" onclick="if (this.value =='Domain Name Search...'){this.value=''}" value="Domain Name Search..." name="domain" id="search-domain-input"> 
    <input type="image" src="<?php bloginfo('template_url'); ?>/inc/img/btn_up_search.png" class="search" name="Search" id="Submit"> 
</form> 

JQuery的

$.ajax(
{ 
    type: 'GET', 
    url : "http://example.com/process.php?domain=", 
    // here you pass js object in convention: { 'query_string' : 'its value' } 
    data : { 'domain' : $('#search-domain-input').val() }, 
    success: function (data) { 


    $("#results").html(data); 
    } 
} 

); 

PHP

if(isset($avail)){ 
    echo '<p>'.$avail.' is available to be registered</p>' 
} else { 
    echo '<p>'.$avail.' is taken register with us for price</p>' 
} 

感謝 喬

+0

你使用jQuery? – Brian 2011-02-17 12:45:40

+0

@布賴恩是啊,必須說我是新來的:) – Joe2010glas 2011-02-17 12:52:41

回答

0

jQuery中(http://jquery.com/),你可以通過使用功能Ajax請求:如果你不想使用jQuery JavaScript庫

$.ajax(
{ 
    url : "url to fetch", 
    success: function (data) { 
    // data is variable that is returned from server as HTML by default, or you can use JSON format 

    $("#content").html(data); 
    } 
} 

); 

,你需要創建xmlhttprequest對象,併爲它建立幫助函數,我不建議這樣做,因爲jQuery可以用於比Ajax調用更多的東西。

編輯:

@comment

簡單地創建process.php在那裏你會接受「域」作爲查詢字符串 - 這將檢查域存在,如果不是應該呼應<p>'$result.'is/isn't available</p>,比$ .ajax的({...});通過該網址和「數據」將可供您使用。

要通過GET與$阿賈克斯(),您可以使用以下設置PARAMS:

$.ajax(
{ 
    type: 'GET', 
    url : "url to fetch", 
    // here you pass js object in convention: { 'query_string' : 'its value' } 
    data : { 'domain' : $('#domain_name_input_field').val() }, 
    success: function (data) { 
    // data is variable that is returned from server as HTML by default, or you can use JSON format 

    $("#content").html(data); 
    } 
} 

);