程序go 2015-05-19 22:55 采纳率: 100%
浏览 29

AJAX,Intel XDK无法正常工作

I have just stated using XDK and I think its an excellent piece of software. I want to use PHP files in my APP and make calls to an XAMPP database.

I am aware that I have to use jquery/AJAX to connect via PHP files.

My first step is just to get an AJAX call to work with JSON. I keep getting error such as access denied, and 404s for the localhost server im targetting.

I have made my PHP files in the XDK is this going to be okay or do I need to place them elsewhere in my htdocs when working with XAMPP. My issue really is that I do not know what Im fixing. I thought targetting my Xampp URL :localhost -> then path to file would do it.

I also do not know if my jquery is working correctly.

Here is my ajax/jquery/index page :

<!DOCTYPE html>

<html lang="en">
  <head>
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
      <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
 <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
   <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
 <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script> 
    <script>
      $(document).ready(function(){
    $("#btn1").click(function(e){
       e.preventDefault(); // prevent the default action of the click
           var fname = $("#name").val();
    $.ajax({

        type:     "GET",
        url: 'http://localhost/nearly/nearly/www/php/test.php;',
        data: {fname: fname},
        dataType: "jsonp",
        jsonp: 'callback',
        jsonpCallback: 'checkname',
        success: function(msg){
           msg=alert("hello");
    }
    });
});
      });

</script>
</head>
<body>

<div data-role="page">
  <div data-role="main" class="ui-content">
    <form method="get"  >
      <label for="name">First name:</label>
      <input id="name" type="text" name="name" id="name">
        <button id="btn1" type="submit">Go</button>
    </form>
  </div>
    <div id="table"></div>
</div>

</body>
</html>

my PHP to handle this is test.php :

<?php     
header("Content-Type: application/json");
 $fname = $_GET['firstname'];


         echo $_GET['checkname'] . '(' . "{'fullname' : '".$fname."'}" . ')';

      }
?>

Im not 100% percent on the JSON above I have rarely used this method but have been told its best for mobile applications.

If possible if someone could give some advice on how to set up XDK with Xampp mySQL and let me know if my code above will return anything to my index page so I know its working.

Can I use php files saved inside my "www" project. Can find absolutley no documentation on setting up XAMPP with XDK. I have access to web servers so can put files on there if this is the only way. I have literally spent 2 long nights trying to fix my issues -

Any help is greatly appreciated. For the Xampp question my project is saved in htdocs of my XAMPP

  • 写回答

2条回答 默认 最新

  • weixin_33726943 2015-05-19 23:42
    关注

    You cannot use php in a Intel XDK project, Intel XDK is for writing apps in HTML, CSS and JavaScript. Your php code to deliver data in JSON format should be hosted on a remote server. The HTML5 app you write can make AJAX calls to get JSON data and display in app.

    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效