如何使用post提交json数据 如何使用php的post提交json数据... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道我有没理解错,希望帮到你form表单中的submit改成buttonJS中做以下三步:1.中先获取你需要的内容2.把数据打包成json格式3.form.submit() 我也想知道,一般来说都是用form提交字段的吧。 以下是一个例子,你可以按需扩展。$post_data = array( 'name'=>'aaa', 'age'=>45, ); $url='http://www.example.com/example.php'; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result=curl_exec($ch); echo $result; a.php$data = array("name" => "testname", "age" => "25");$data_string = json_encode($data);$ch = curl_init('http://localhost/test/a.php');curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));$data = curl_exec($ch); print_r($data);b.php1.echo file_get_contents("php://input");2.echo $GLOBALS["HTTP_RAW_POST_DATA"];1或2均可获取到由a.php页面传过来的json数据 json就是字符串,大的字符串用post小的用get方式不就可以了。 http错误:406拒绝访问 静态页面调用动态数据问题 PHP LINUX 服务器高手进! jquery php 传值问题 php播放视频代码。 discuz的程序打不开了,提示(1045) notconnect smarty 这样做,达到缓存的效果 了吗? ECshop显示第二张缩略图 求curl系列函数的更深入了解的博客或网站地址 php5.6不兼容问题 求解zend加密 怎么在post结果页打印出数据来源页网址?
form表单中的submit改成button
JS中做以下三步:
1.中先获取你需要的内容
2.把数据打包成json格式
3.form.submit()
$post_data =
array(
'name'=>'aaa',
'age'=>45,
);
$url='http://www.example.com/example.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
echo $result;
$data = array("name" => "testname", "age" => "25");
$data_string = json_encode($data);$ch = curl_init('http://localhost/test/a.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
$data = curl_exec($ch); print_r($data);b.php
1.echo file_get_contents("php://input");
2.echo $GLOBALS["HTTP_RAW_POST_DATA"];1或2均可获取到由a.php页面传过来的json数据