2

以下の API は完全に機能しており、「plan-api.php」から適切な出力が得られています。

PHPコード(plan-api.php)

if ($_GET['result']):
$rslt = $_GET['result'];
$result = Unirest\Request::get("https://sphirelabs-mobile-number-portability-india-operator-v1.p.mashape.com/index.php?number=$rslt",
array(
"X-Mashape-Key" => "XXXXXXXXXX",
"Accept" => "application/json"
)
);

$optid= rawurlencode($result->body->Operator);
$cirid=rawurlencode($result->body->{'Telecom circle'});

endif;  


// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"X-Mashape-Key: XXXXXXXXX"               
 )
 );

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$requestUrl = "https://tariff-plan-api-datayuge.p.mashape.com/index.php?circleid=$cirid&limit=50&operatorid=$optid&recharge_type=3g";
$response = (file_get_contents($requestUrl, false, $context));

$data = json_decode($response, true);

$data2= json_encode($data);

echo $data2;

出力 (plan-api.php から)

{"data":[{"id":"4401","operatorid":"Reliance GSM","circleid":"Bihar Jharkhand","recharge_amount":"60","recharge_talktime":"60","recharge_validity":"NA ","recharge_shortdesc":"Recharge of Rs 60 By Reliance GSM","recharge_longdesc":"Full Talktime ","recharge_type":"Full Talktime"},{"id":"4407","operatorid":"Reliance GSM","circleid":"Bihar Jharkhand","recharge_amount":"110","recharge_talktime":"110","recharge_validity":"Lifetime Validity","recharge_shortdesc":"Recharge of Rs 110 By Reliance GSM","recharge_longdesc":"Full Talktime ","recharge_type":"Full Talktime"},{"id":"4409","operatorid":"Reliance GSM","circleid":"Bihar Jharkhand","recharge_amount":"150","recharge_talktime":"150","recharge_validity":"Lifetime Validity","recharge_shortdesc":"Recharge of Rs 150 By Reliance GSM","recharge_longdesc":"Full Talktime ","recharge_type":"Full Talktime"},{"id":"4414","operatorid":"Reliance GSM","circleid":"Bihar Jharkhand","recharge_amount":"555","recharge_talktime":"600","recharge_validity":"Lifetime Validity","recharge_shortdesc":"Recharge of Rs 555 By Reliance GSM","recharge_longdesc":"Extra Talktime","recharge_type":"Full Talktime"}]}

HTML/AJAX(plan-ajax.php)

circleidここで、 andの値を入力するとテキストボックスに出力が得られますoperatoridが、最初のAPIのphpオブジェクト出力を入力しようとすると、テキストボックスの下に出力が得られません。$optid$cirid;

$('#opt'+key).val(value.operator);テキストボックスID「opt」で追加しようとしましたが、同じ出力がありません

Please enter a Mobile number
<input type="text" id="search">
<br>


<input type="text" id="result0">
<input type="text" id="result1">
<input type="text" id="result2">
<input type="text" id="result3">
<br>
<input type="text" id="talk0">
<input type="text" id="talk1"> 
<input type="text" id="talk2">
<input type="text" id="talk3">


<script>
$(document).ready(function() {
$('#search').keypress(function(){
    $.ajax({

        type: "GET",
        url: "plan-api.php",
        data: 'result=' + $('#search').val(),
        dataType: "json",

        success: function(responseText){

            $.each(responseText.data, function(key,value){

    $('#result'+key).val(value.recharge_amount);
       $('#talk'+key).val(value.recharge_talktime);

            });
        }

    }); // Ajax Call
}); //event handler

}); //document.ready
</script>
4

1 に答える 1