如何从PHP REST WEBSERVICE获取选项

时间:2017-11-12 01:27:10

标签: php ajax web-services phonegap

我可以使用来自其他网络服务的ajax填充一个select标签(我没有代码,我的专业人员只是提供网址)但是我尝试并且没有工作< / p>

我的ajax代码:

<form method="GET" type="REST">  
    <select name="campus" id="campus" type="option" value="codCampus">

            <script type="text/javascript">  
               $.ajax({
                type: "GET",
                dataType: "json", // i try put option and also didnt work
                url: "http://191.252.96.136/plesk-site-preview/pimsorocaba.com.br/191.252.96.136/webpim.php?tipo=option&tabela=Campus&campo=campus&valor=codCampus",
                success: onSuccess,
                error: onError
              });
            </script>
    </select>

    <select name="periodo" id="periodo" type="option" value="codPeriodo">
    </select>

    <select name="curso" id="curso" type="option" value="codCurso">
    </select>         
</form>

1 个答案:

答案 0 :(得分:0)

在您请求数据的网址中,没有标题,因此您需要安装Chrome扩展程序。 https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

我给你的建议,请你的教授在api中加入一个cors。所以请遵循代码。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>

<form method="GET" type="REST">
  <select name="campus" id="campus" type="option" value="codCampus">


  </select>

  <select name="periodo" id="periodo" type="option" value="codPeriodo">
  </select>

  <select name="curso" id="curso" type="option" value="codCurso">
  </select>
</form>

<script type="text/javascript">
   $.ajax({
    type: "GET",
    url: "http://191.252.96.136/plesk-site-preview/pimsorocaba.com.br/191.252.96.136/webpim.php?tipo=option&tabela=Campus&campo=campus&valor=codCampus",
    crossDomain: true,
    success: function(response) {
        $('#campus').html(response)
    },

  });

</script>