Calling PHP script with Cordova

user1433479

I'm working on an app that's supposed to contain the same information as an already existing website.

What I wanted to do was create a Cordova app that calls an external PHP script which in turn gets information from the database that the website is using.

Right now I'm working on calling the PHP script but it just doesn't seem to work.

Here is the script I'm trying to call:

<?php
 $a = 1;
 $b = json_encode($a);
 return $b;
?>

Ofcourse this is just to test the connection. The URL for this file is http://localhost:8888/get_posts.php

Here is the code for the app:

$('#page1').bind('pageshow', function () {
    $.get('localhost:8888/get_posts.php', function (data) {
        $(this).find('.homeText').html(data);
    });
});

This fetches the file whenever the page is shown (handy) and then puts the new data into the page. The problem is that the page remains empty at all times, when it should be showing a "1". Can anyone see where it goes wrong?

Error message: XMLHttpRequest cannot load localhost:8888/get_posts.php. Cross origin requests are only supported for HTTP.

UPDATE: The error message dissapeared when adding http:// to the url, but the problem persists.

I've changed the code to:

$('#page1').bind('pageshow', function () {
    $.get('localhost:8888/get_posts.php', function (data) {
        alert(data);
    });
});

and it shows me an empty alert box.

Solution: Had to use echo instead of return for the script to show me a result. http:// was also required so the script is allowed to communicate.

delueg

You have to 'echo' your response not returning it like so

<?php
 $a = 1;
 $b = json_encode($a);
 echo $b;
?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a PHP script using ajax

From Dev

Calling a Python Script from PHP

From Dev

Calling a PHP script using ajax

From Dev

Calling a php script at regular intervals with javascript

From Dev

php calling bash script with multiple commands issue

From Dev

Calling a Google App Script from PHP?

From Dev

Calling a php script using ajax not working

From Dev

php calling bash script with multiple commands issue

From Dev

What is the '?' in a href when calling a php script?

From Dev

Calling a PHP script using FreePBX and Asterisk

From Dev

JavaScript function inside echo in PHP script is not calling

From Dev

Python script calling PHP script while passing $_GET parameters

From Dev

Python script calling PHP script while passing $_GET parameters

From Dev

Calling node.js script from PHP returns nothing

From Dev

Calling jquery function after certain php script with parameters

From Dev

php calling variables from another script to assign for the session

From Dev

PHP script unable to gather filename of calling html page

From Dev

Having issue with chart generation by calling another php script

From Dev

Internal server error 500 when calling php script

From Dev

script calling another script?

From Dev

Cordova Contact Picker Plugin Calling

From Dev

Execute script in Cordova Webview

From Dev

Calling next script on Tkinter

From Dev

Is calling a script in unityscript slow?

From Dev

Calling function in Shell script

From Dev

calling script on few pages

From Dev

Java script not calling in html

From Dev

Polymer calling functions in script

From Dev

Trivial Cordova plugin not calling native function

Related Related

HotTag

Archive