简体   繁体   English

PhoneGap GET Ajax请求返回注释内容

[英]PhoneGap GET Ajax request returns commented content

index.html 的index.html

    <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title>Blank App</title>
        <script src="assets/js/jquery-3.1.1.min.js"></script>
    </head>
    <body>
        <script type="text/javascript" src="cordova.js"></script>
        <script>
            window.onload = function(){
                $.ajax({
                    url: "ajax/app.php",
                    type: "GET",
                    datatype:"text",
                    success: function(result){
                        $("#main_div").html(result);
                    }
                });
            }
        </script>

        <p id="main_div"> Hello World </p>
    </body>
</html>

app.php app.php

<?php
    header(Access-Control-Allow-Origin: *);
    header('Access-Control-Allow-Methods: GET, POST');  
    echo "ok";
 ?>

config.xml config.xml中

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>Test</name>
    <description>
        A blank PhoneGap app.
    </description>
    <author email="support@phonegap.com" href="http://phonegap.com">
        PhoneGap Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
</widget>

returning request in the developer console 在开发者控制台中返回请求

<!--?php
    header(Access-Control-Allow-Origin: *);
    header('Access-Control-Allow-Methods: GET, POST');  
    echo "ok";
 ?-->

ajax returns commented request and when i change ajax type to POST it gives error : POST http://ip:3000/ajax/app.php 404 (Not Found) Help please ! ajax返回注释请求,当我将ajax类型更改为POST时,它会给出错误:POST http:// ip:3000 / ajax / app.php 404(Not Found) 请帮助!

There is 2 possible causes to your problem. 您的问题有两种可能的原因。

1.) If you have your PHP files inside of your phonegap www folder this is wrong. 1.)如果你的phonegap www文件夹中有你的PHP文件,这是错误的。 You need to host your PHP files on a server. 您需要在服务器上托管PHP文件。 You can either pay for one and put your PHP files on there or you can alternatively download a program like xampp run a php server on your computer and connect to the server via your wifi connection from your phone. 您可以支付一个并将PHP文件放在那里,或者您也可以下载程序,如xampp在您的计算机上运行php服务器并通过手机的wifi连接连接到服务器。 The url for ajax would then look like http://192.168.0.4/ajax/file.php . 然后,ajax的url看起来像http://192.168.0.4/ajax/file.php The 192.168.0.4 is the ip address of the computer running the Xampp server you can get this ip by opening command prompt and running ipconfig /all on the computer that is hosting the xampp server and use the local iP4 address. 192.168.0.4是运行Xampp服务器的计算机的IP地址,您可以通过打开命令提示符并在托管xampp服务器的计算机上运行ipconfig / all并使用本地iP4地址来获取此IP。

2.) You are hosting on a server however you haven't entered the full IP. 2.)您正在服务器上托管但是您还没有输入完整的IP。

ajax/app.php => Wrong ajax / app.php =>错了

http://ipaddress/ajax/file.php => Right http://ipaddress/ajax/file.php =>对

J Ĵ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM