Ⅰ js到底如何将一堆数组通过post的方法发送给php
如果有其他参数可以将数组转换为json字符后,再将转换的结果赋值给一个参数,内通过Ajax的post提交容给PHP
序列化可以用jquery.serialize();
json:JSON.stringify(arr).toString();
Ⅱ JS加密不可靠,用post方法行吗
如果那段代码是用来处理数据可以用ajax来实现。
我简单举个例子比如这个函数
functioncount(a){
returna+=10;
}
参数 a 返回值+10,但是我们不想让别人知道函数内部是怎么处理的
我们可以把处理的过程移到后台,这里我后台用php举例 test1.php
<?php
$num=$_POST['num'];//取前台的参数值
$num+=10;//计算
echo$num;//返回
?>
然后在前端用ajax传参数到后台,得到计算的返回值,我这里用jquery的post
<scriptsrc="http://code.jquery.com/jquery-latest.js"></script>
<script>
window.onload=function(){
varnum=2;
alert(count(num));
$.post('test1.php',{num:num},function(s){
alert(s)
})
}
functioncount(a){
returna+=10;
}
</script>
运行这段代码,就可发现alert(count(num)); 与post回传的alert(s)值是一样的,但是用post别人是看不到 += 10这段后台处理过程的
原理就是这么简单
Ⅲ js 模拟POST提交enctype="multipart/form-data"类型的表单
只是需要文件上传才用它的
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
改成
xmlHttp.setRequestHeader("Content-Type","multipart/form-data;")。
Ⅳ js像这样发送json到php,为什么$_POST为空如何做
首先,尽可能利用jquery的ajax来发送数据,这样它会自动把你的json编码成x-www-form-urlencode的格式,这样php的$_POST就能获得数据了。
如果一定要用原生js来做ajax,那就要自己来实现编码和解码,比如这样:
httpRequest=newXMLHttpRequest();
httpRequest.open("POST",$url,true);
httpRequest.setRequestHeader("Content-Type","application/json");
vararr=["124","424","aab","cdf","哈哈哈"];
varstr=JSON.stringify(arr);
httpRequest.send(str);
PHP端:
$data=file_get_contents('php://input');
$arr=json_decode($data,true);
print_r($arr);
Ⅳ JS发送json格式POST请求有哪些方式
以Ajax方式发送
<scripttype="text/javascript">
一、获取url所有参数值
functionUS(){
varname,value;
varstr=location.href;
varnum=str.indexOf("?");
str=str.substr(num+1);
vararr=str.split("&");
for(vari=0;i<arr.length;i++){
num=arr[i].indexOf("=");
if(num>0){
name=arr[i].substring(0,num);
value=arr[i].substr(num+1);
this[name]=value;
}
}
}
二、使用JS发送JSON格式的POST请求
varus=newUS();
varxhr=newXMLHttpRequest();
xhr.open("POST","/searchguard/api/v1/auth/login",true);
xhr.setRequestHeader("Content-type","application/json");
xhr.setRequestHeader("kbn-version","5.3.0");
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
window.location.href=us.nextUrl;
}
}
};
xhr.send(JSON.stringify({
"username":us.u,
"password":us.p
}));
</script>
Ⅵ 怎么用javascript发送post请求
第一种提交post的方式是传统方式,判断浏览器进行post请求。
<SCRIPT stype=text/javascript>
var xmlobj; //定义XMLHttpRequest对象
function CreateXMLHttpRequest()
{
if(window.ActiveXObject)
//如果当前浏览器支持Active Xobject,则创建t对象
{
//xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
try {
xmlobj = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlobj = false;
}
}
}
else if(window.XMLHttpRequest)
//如果当前浏览器支持XMLHttp Request,则创建XMLHttpRequest对象
{
xmlobj = new XMLHttpRequest();
}
}
function SubmitArticle(act,cityname,antique) //主程序函数
{
CreateXMLHttpRequest(); //创建对象
//var parm = "act=firstweather" ;//构造URL参数
//antique = escape(antique);
var parm = "act=" + act + "&cityname=" + cityname + "&antique=" + antique;//构造URL参数
//xmlobj.open("POST", "{dede:global.cfg_templeturl/}/../include/weather.php", true); //调用weather.php
xmlobj.open("POST", "/weather/include/weather.php", true); //调用weather.php
xmlobj.setRequestHeader("cache-control","no-cache");
xmlobj.setRequestHeader("contentType","text/html;charset=uft-8") //指定发送的编码
xmlobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); //设置请求头信息
xmlobj.onreadystatechange = StatHandler; //判断URL调用的状态值并处理
xmlobj.send(parm); //设置为发送给服务器数据
}
第二种方式则是虚拟表单的形式提交post请求
function post(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
// alert(opt.name)
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
调用方法 如:
复制代码 代码如下:
post('pages/statisticsJsp/excel.action', {html :prnhtml,cm1:'sdsddsd',cm2:'haha'});
Ⅶ jsp页面使用js或者jQuery 向一个地址Post提交表单,参数LinkId ..获取到这个地址返回的信息...求代码
建议你使用jQuery form 提交表单 提交的地址 提交方法在form定义
需要引入
jQuery.min.js
jQuery.form.js
jQuery.ajaxSubmit({
dataType:'json',//返回的信息 大量数据使用json方便 如果只是几个字符 使用text
success:function(data){
//你处理信息的方法
}
});
使用的是AJAX
如果你要传的值用get就能满足的话 jQuery.ajax也可以使用 而且方便