开发者

using javascript to post json data to a url

开发者 https://www.devze.com 2023-03-26 04:54 出处:网络
I have some json data existed in a php file that needs to be posted to a url by using javascript. But i dont know Howto?

I have some json data existed in a php file that needs to be posted to a url by using javascript. But i dont know Howto?

$param_fields = array(
            'format'=> 'json',
            'event'=> 'revert',
            'api_key' => '23423'
        );
$encoded_params = json_encode($param_fields); \\$encoded_params should be posted


$url = "www.example.com/lt"

I hope through clicking a button to post the json data mentioned above, e.g.

echo "<input type='button' value='post json' onclick= 'post_json_data($url, $encoded_params)'>" 
开发者_如何学编程


You can use jQuery.get() if you want simplicity.

example:

$.get("test.php", { name: "John", time: "2pm" } );

or check this if you only want to use javascript : http://www.webreference.com/programming/javascript/kh/column2/

0

精彩评论

暂无评论...
验证码 换一张
取 消