ASP.NET: jQuery AJAX 'data' param problem

前端 未结 3 1300
温柔的废话
温柔的废话 2020-12-16 13:49

I\'ve been having problems with this code I had spent the last 3 hours digging around and trying to find an answer. As I wasn\'t successful, I will just post the code and as

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 14:42

    Although this is an older post I thought I would contribute. I have been sending an associative array same idea an the accepted post I just find it easier to write.

    Javascript

    postData[0] = 'data!';
    postData[1] = 'moar data!';
    postData[2] = 'and some data';
    
    $.ajax({
        type: 'POST',
        url: 'postUrl',
        data: { data: postData },
    });
    

    PHP

    $data = $_POST['data'][0];
    $moar_data = $_POST['data'][1];
    $and_some_data = $_POST['data'][2];
    

提交回复
热议问题