fcreav
fcreav

Reputation: 360

AJAX, intel XDK not working

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

Upvotes: 3

Views: 1939

Answers (2)

fcreav
fcreav

Reputation: 360

I have this working. It was largely the xampp that I have got some (under statement) help with thanks to @TasosAanastasiou.

To use XDK with xampp you have to set up a virtual server ( I think this is the right term). This involves logging on to your router and port forwarding on port 80. The type of application being HTTP web server. When complete you should be able to from a browser type http://your_ip/xammp and get the xampp homepage. Note you can now get this homepage with both 127.0.0.1 (as normal) and with your your_ip. Then in your XDK your Urls in your scripts will use http://your_ip/xampp/path to folder In htdocs.

Or

http://your_ip/path to folder In htdocs.

Note: I had some issues where I had to change my apache config file to do with xampp new security protocol......

I used an answer on here again advice from @TasosAanastasiou

It now works perfectly and I have my xdk working with Xampp and MySQL

I will post link.

This is the original question it went into chat so an answer is not posted Intel XDK, AJAX and XAMPP mySQL connection

This is the apache link : Error when trying to access XAMPP from a network

Is was not the question Tasos directed me to .the solution was to comment out "deny from all" and add in "allow from all "as the above question states.

This error came after the port forwarding exercise. And if you are talking to xampp you probably close.

Upvotes: 0

krisrak
krisrak

Reputation: 12952

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.

Upvotes: 1

Related Questions