dongmi9494 2012-09-29 01:36
浏览 39

Jquery $ .post方法不起作用[关闭]

Background: I'm using Apache with XAMPP to set up localhost. I'm relatively new to programming, and very new to PHP. I'm trying to call a PHP file in the same directory as my Javascript file, but the code I'm using doesn't seem to work. Here's a sample:

Javascript:

function SendPhps(){
var point = 2;'
$.post('json.php',point);}
$(document).ready(function(){
SendPhps();
});

PHP:

<?php
if(!empty($_POST)){
file_put_contents('example.txt','Itworks');
}
?>

EDIT: Ok, I've revised my scripts to be more simple, but opening my page still doesn't trigger any alert box:

PHP:

<?php
    if (empty($_POST))
        echo "empty";
    else
        echo "not empty";
?>

Javascript:

$(document).ready(function() {
    var point = {'param':2};
    $.post(
        'json.php', 
        point, 
        function(data){
            alert(data);
        }
    );
});
  • 写回答

1条回答 默认 最新

  • douzhu1188 2012-09-29 01:59
    关注

    Your var point needs to have a more meaningful structure than that. What does '2' mean to a post? Nothing really. Give it a name. i.e.

         var point = {'html':2};
    

    and since you're just learning, don't try to do multiple things at once like writing to a file. Keep it simple. Just have your PHP echo your result.

    Here is an example on jsfiddle using their 'echo/html' URL - which simply echos out whatever value you set to the 'html' parameters.

    http://jsfiddle.net/k5ygv/

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)