写入服务器上的文件的JavaScript输出 [英] Write javascript output to file on server

查看:106
本文介绍了写入服务器上的文件的JavaScript输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个测试用户的屏幕分辨率这个HTML文件,然后使用Javascript安装的插件。因此,当用户访问该页面就看到:(EG)您当前的屏幕分辨率为1024x768,并且您已经安装了以下插件:插件No.2- Java部署工具包7.0.10.8 [地点:npdeployJava1.dll],插头 - 在No.3-的Java(TM)平台SE 7 U1 [地址:npjp2.dll],插件No.4-的Microsoft Office 2003【地点:NPOFFICE.DLL] ...我还需要保存的信息文件在服务器上。所有的用户在Firefox或Chrome。如何做到这一点使用AJAX?

So I have this HTML file that tests the user's screen resolution, and plugins installed using Javascript. So when the user accesses the page it sees: (e.g.) Your current screen resolution is 1024x768 and you have the following plugins installed: Plug-in No.2- Java Deployment Toolkit 7.0.10.8 [Location: npdeployJava1.dll], Plug-in No.3- Java(TM) Platform SE 7 U1 [Location: npjp2.dll], Plug-in No.4- Microsoft Office 2003 [Location: NPOFFICE.DLL]... I also need to save this information in a file on the server. All users are having firefox or chrome. How do I do this using AJAX?

<html>
<body>
<script language="JavaScript1.2">
document.write("Your current resolution is "+screen.width+"*"+screen.height+"")
</script>
<BR><BR>
<SCRIPT LANGUAGE="JavaScript">
var num_of_plugins = navigator.plugins.length;
for (var i=0; i < num_of_plugins; i++) {
var list_number=i+1;
document.write("<font color=red>Plug-in No." + list_number + "- </font>"+navigator.plugins[i].name+" <br>[Location: " + navigator.plugins[i].filename + "]<p>");
}
</script>
</body>
</html>

感谢

推荐答案

如果没有的jQuery(原始的JavaScript):

Without jQuery (raw JavaScript):

    var data = "...";// this is your data that you want to pass to the server (could be json)
    //next you would initiate a XMLHTTPRequest as following (could be more advanced):
    var url = "get_data.php";//your url to the server side file that will receive the data.
    var http = new XMLHttpRequest();
    http.open("POST", url, true);

    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");

    http.onreadystatechange = function() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);//check if the data was received successfully.
        }
    }
    http.send(data);

使用 jQuery的

$.ajax({
  type: 'POST',
  url: url,//url of receiver file on server
  data: data, //your data
  success: success, //callback when ajax request finishes
  dataType: dataType //text/json...
});

我希望这有助于:)

I hope this helps :)

更多信息:

  • <一个href="https://www.google.com/search?rlz=1C1AVSC_enIL436IL436&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8&q=js%20ajax%20post" rel="nofollow">https://www.google.com/search?rlz=1C1AVSC_enIL436IL436&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8&q=js%20ajax%20post

https://developer.mozilla.org/en-US/docs/Web/API/XMLHtt$p$pquest/Using_XMLHtt$p$pquest

这篇关于写入服务器上的文件的JavaScript输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆