【问题标题】:using javascript to post json data to a url使用 javascript 将 json 数据发布到 url
【发布时间】:2011-08-04 21:45:51
【问题描述】:

我的 php 文件中存在一些 json 数据,需要使用 javascript 将其发布到 url。但是我不知道怎么做?

$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"

我希望通过点击一个按钮来发布上面提到的json数据,例如

echo "<input type='button' value='post json' onclick= 'post_json_data($url, $encoded_params)'>" 

【问题讨论】:

  • 忽略 PHP 语法错误,如果您发布 JS post_json_data() 函数可能会有所帮助。

标签: php javascript json http post


【解决方案1】:

如果您想要简单,可以使用jQuery.get()

示例:

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

如果您只想使用 javascript,请勾选此项:http://www.webreference.com/programming/javascript/kh/column2/

【讨论】:

    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    相关资源
    最近更新 更多