duanji1482 2014-12-07 00:42
浏览 38
已采纳

Jquery将变量发送到php然后发送到.txt文件? [关闭]

My apologies 1st of all for the code Im about to post... What I want to do is use the JQuery post method or similar to post 2 variables to a php file and then have the php post it to a .txt file I need the post method to be in a function and when that function is called have jquery post the 'score' this is the function:

function onGameOver(){
if (-1 < score && score < 6) { doStuff(); }
 if (5 < score && score < 9) { doStuff2(); }
if (8 < score && score < 15) { doStuff3(); }
if (14 < score && score < 21) { doStuff4(); }           
if (20 < score && score < 27) { doStuff5(); }
if (26 < score && score < 31) { doStuff6(); }
if (30 < score && score < 36) { doStuff7(); }
if (35 < score && score < 51) { doStuff8(); }
if (50 < score && score < 69) { doStuff9(); }
//post method here
}

I've no idea how to go about this and I've tried but failed any ideas on how to set this up the vars I want to be posted are var hiScore and var userip

Thank you for any help sorry for no code to start off ! I dont have any exp with php nor the jquery post method. Thank you are reading.

  • 写回答

2条回答 默认 最新

  • dongma2388 2014-12-07 01:12
    关注

    Here's a little inside in a jQuery ajax call and the php functions fopen, fwrite and fclose. You need to fetch var hiScore and var userip in your first file, create a new php file and put the contents for php in there.

    AJAX CALL: SEE JQUERY AJAX

    $.ajax({
        url:'file.php',
        type:'post',
        data:{hiScore:hiScore,
              userip:userip},
        success:function(data){
        alert('Success');}
    });
    

    WRITE TO FILE IN PHP: SEE PHP.NET

    $hiScore = $_POST['hiScore'];
    $userip = $_POST['userip'];
    $file = fopen('file.txt','w+');
    fwrite($file, $hiScore.'\t'.$userip);
    fclose($file);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写