Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未在表中追加Ajax成功_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 未在表中追加Ajax成功

Javascript 未在表中追加Ajax成功,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个关于我大学小项目的技术问题。教授给我的任务如下 我们假设有一个静态表,其中包含例如3个域名,以便在域可用性API上提供更高的性能 -------------------------------------------------- |example1.com | $9.99 / year | Select Button | -------------------------------------------------- |example2.net | $12.99 / ye

我有一个关于我大学小项目的技术问题。教授给我的任务如下

我们假设有一个静态表,其中包含例如3个域名,以便在域可用性API上提供更高的性能

-------------------------------------------------- |example1.com | $9.99 / year | Select Button | -------------------------------------------------- |example2.net | $12.99 / year | Select Button | -------------------------------------------------- |example3.org | $6.99 / year | Select Button | --------------------------------------------------
您的API是否返回正确的值

我不确定它是否有效

var index = $('.btn-primary').index(this);
if (data == 1) {
    /* change "Select Button" to "Selected"*/
    $('.btn-primary:eq(' + index + ')').html('Selected');
} else {
    /* change "Select Button" to "Not Available"*/
    $('.btn-primary:eq(' + index + ')').html('Not Available');
}

您是否在浏览器的开发人员工具中观看了AJAX请求/响应?您是否将jQuery库包括在项目中?是否报告了任何错误?您是否在web服务器上运行此功能?当然,是的,我不想在代码中发布所有内容,因为大家都知道如何包含jquery.min.jsp,但不是每个人都知道。;-)你的问题到底是什么?我不能将“选择”按钮更改为上面解释的文本“已选择”或“不可用”。当然,我的API工作得很好,我只是没有发布真正的链接,因为它来自大学。如果这是正确的答案,那么问题就完全不充分了。它没有显示他用来更改select按钮的代码,那么人们怎么知道他做错了什么以及这是如何修复的呢?他只是想把jquery代码放入ajax成功函数中。。。没关系,只要记住,在现实生活中,你在大学里走的捷径会影响你的成功。确保你明白他在那里做了什么。。。 -------------------------------------------------- |example1.com | $9.99 / year | Not Available | -------------------------------------------------- |example2.net | $12.99 / year | Select Button | -------------------------------------------------- |example3.org | $6.99 / year | Select Button | -------------------------------------------------- -------------------------------------------------- |example1.com | $9.99 / year | Not Available | -------------------------------------------------- |example2.net | $12.99 / year | Selected | -------------------------------------------------- |example3.org | $6.99 / year | Selected | --------------------------------------------------
<table>
    <tbody>
        <tr>
            <td class="domain">example1.com</td>
            <td>$9.99 / year</td>
            <td class="changebtn"><button type="button" class="btn btn-primary">Select</button></td>
        </tr>
        <tr>
            <td class="domain">example2.net</td>
            <td>$12.99 / year</td>
            <td class="changebtn"><button type="button" class="btn btn-primary">Select</button></td>
        </tr>
        <tr>
            <td class="domain">example3.org</td>
            <td>$6.99 / year</td>
            <td class="changebtn"><button type="button" class="btn btn-primary">Select</button></td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
    $(document).on('click', '.btn-primary', function (e) {
        e.preventDefault();
        var domain = $(this).closest('tr').children('td.domain').text();
        $.ajax({
            type: "GET",
            async: true,
            url: "domainapi.php",
            //`enter code here`
            data: {
                domain: domain
            },
            success: function (data) {
                if (data == 1) {
                    /* change "Select Button" to "Selected"*/
                } else {
                    /* change "Select Button" to "Not Available"*/
                }
            }
        });
    });
</script>
$domain = $_GET["domain"];
$checkdomain = "https://api.example.com/xml.response?&Domain=$domain";
$data = file_get_contents($checkdomain);
$xml = simplexml_load_string($data);
if( ! $xml)
{echo "unable to load XML file";}
else
{
foreach ($xml->CommandResponse->DomainCheckResult as $result)  {
$checkavailablity =  $result["Available"];
$checkprice       =  $result["PremiumRegistrationPrice"];
if (($checkavailablity == "true") && ($checkprice == "0"))
{echo 1;}
/*Ajax success: function(data) will return 1 and then we decided in the above success function to change the "Select Button" to "Selected"*/
else {echo 0;}
/*Ajax success: function(data) will return 0 and then we decided in the above success function to change the "Select Button" to "Not Available"*/
}
}
var index = $('.btn-primary').index(this);
if (data == 1) {
    /* change "Select Button" to "Selected"*/
    $('.btn-primary:eq(' + index + ')').html('Selected');
} else {
    /* change "Select Button" to "Not Available"*/
    $('.btn-primary:eq(' + index + ')').html('Not Available');
}