duanjue2560 2015-11-27 14:15
浏览 62

通过AJAX将数据发送到PHP可以在localhost中运行,但不能在远程服务器上运行

I'm trying to host the files repo_display.php ---> repo_ajax.js ---> repo_action_with_DB.php --->return to repo_display.php. This works great on my localhost but once I publish it to the server it doesn't work.

When I submit repo_display.php form to call AJAX, it transfers me to the server page with the error message "error 403 - forbidden"

I try change permissions of js to 755-700 and it's works unless AJAX , it's forbidden to access repo_action_with_DB.php although I change their permission too ! . I try to access the page without submit the form it's display same problem

403 error forbidden Uncaught ReferenceError: prettyPrint is not defined

repo_display.php

<html>
<head>
                <!-- report java script -->
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type='text/javascript' src='scripts/repo_ajax.js'> </script>
</head>
<body>
            <form action="" id="report">
    <legend style="margin-left:40px;">text : </legend>

    <p id="success" class="success"></p>
    <input id="radio1" name="radio" value="Publisher" type="radio" onclick="radioClicked1()" required>
    <input id="radio2" name="radio" value="Journal" type="radio" onclick="radioClicked2()" >
    <input   name="title1" type="text" required>                    
    <input  id="ISSN" name="ISSN" type="text" required>                       
    <input id="url" name="url" type="url" required><br>
    <input type="text" value="1" style="display:none;"/>
    <input  type ="submit" value="Save"/>
                            </form>
</body>
</html>

repo_ajax.js

$(document).ready(function () {

    $("#send").click(function () {

        var type;
        if (document.getElementById('radio1').checked) {
            type = document.getElementById('radio1').value;
        }
        else if (document.getElementById('radio2').checked) {
            type = document.getElementById('radio2').value;
        }
        var title1 = document.getElementById('title1').value;
        var ISSN = document.getElementById('ISSN').value;
        var url = document.getElementById('url').value;


        if (type == 'Journal' && ISSN == '') {
            $("report")[0].checkValidity();
        }
        else if (type == '' || title1 == '' || url == '') {
            // alert("fill all required fields !");
            ("report")[0].checkValidity();
            if (type == 'Journal' && ISSN == '') {
                $("report")[0].checkValidity();
            }
        }
        else {
            var r = confirm
                    ("Are you sure to send this Report ?");
            if (r == true)
            {

                $.ajax({
                    type: "GET",
                    url: "repo_action_with_DB.php",
                    data: "radio=" + type + "&title1=" + title1 + "&ISSN=" + ISSN + "&url=" + url,
                    success: function (data) {
                        if (data == 1)
                        {
                            $("#success2").html("Done");

                        }
                        else if (data == 2)
                        {
                            $("#success").html("Your Report is exist already");

                        }
                        else
                        {
                            $("#success").html("Faild  ,please try again !");

                        }
                    }
                });
            }
        }
        return false;

    });

});
function radioClicked1() {
}
function radioClicked2() {
}

repo_action_with_DB.php

<?php

ob_start();
//------------------Database section------------------------------------------
include('database.php');
//------------------Get the data ------------------------------------------

$title = $_GET['title1'];
$type = $_GET['radio'];
$url = $_GET['url'];
// ----------------------add -----------------------------------

if ($type == "k") {
    $IS = $_GET['IS'];
    $qry ="SELECT k_name FROM k where ISSN = '".$IS."'";
    $result = mysql_query($qry);
    if (mysql_num_rows($result) == 1) {
          echo '2';

    }
    else {
    $qry1 = "insert into k (`k_name`, `IS`, `URL`, `is_r`) values('" . $title . "','" . $IS . "','" . $url . "',1);";
    $result1 = mysql_query($qry1);
    if ($result1) {
        echo '1';
    }
}   
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line