weixin_33691700 2013-05-03 12:19 采纳率: 0%
浏览 7

从ajax获取数据

im trying to send data with ajax:

var id_cookie = read_cookie('replay_id');
id_cookie = JSON.stringify(id_cookie);
$.ajax({
        url: remote_ip+':8124/show_replay',
        data: {cookie: id_cookie},
        dataType: "jsonp",
        jsonpCallback: "start_replay",
        cache: false,
        timeout: 5000,
        success: function(data) {
            console.log("Received data: "+data);
            console.log(data);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert('error ' + textStatus + " " + errorThrown);
        }
});

and when I receive it I want to access the data

else if (req.method === "GET") {

// do something with the sent data here. req.data is undefined. How can I reach it?

  • 写回答

1条回答 默认 最新

  • ~Onlooker 2013-05-03 12:22
    关注

    In PHP, to get the value of "cookie" as a GET parameter, you can use:

    $_GET["cookie"]
    

    If you're not sure if it will be GET or POST, you can use:

    $_REQUEST["cookie"]
    

    I'd probably change the name of the data you're sending from "cookie" to something less ambiguous, to avoid confusion with actual cookies.

    评论

报告相同问题?