Ajax将json对象发送到服务器并接收服务器发回的json对象回到ajax(Calling page)

时间:2015-10-11 21:33:11

标签: php json ajax

我有index.php页面,其中我有一个html表单,提交我想要AJAX调用my.php php页面(这样页面不应该重新加载)我在ajax中使用post将POST数据发送给我.php页面。在my.php页面上,我想将JSON对象发送到某个服务器,作为回报,该服务器将向我发送另一个JSON对象。现在我想在我的页面index.php(在ajax然后在索引php上)收到这个收到的JSON对象我想解析那个json对象以获取单个值。

这是我的代码,请我第一次做AJAX,请帮我编写代码。

%// Vectorize : "g(:, i) = g(:, i) - sum(log(sigma(i, :)))"
parte1 = bsxfun(@minus,g,sum(log(sigma),2).'); %//'

%// Vectorize : "bsxfun(@minus, x, mu(i, :)).^2"
parte2_1 = bsxfun(@minus,x,permute(mu,[3 2 1])).^2;

%// Vectorize : "bsxfun(@rdivide, ...*sigma(i, :).^2)"
parte2 = bsxfun(@rdivide,parte2_1,2*permute(sigma,[3 2 1]).^2);

%// Squeeze in dimensions of the BSXFUN extended array and subtract from parte1
g = parte1 - squeeze(sum(parte2,2));

MY.PHP页面内容

$("#ok").on('submit', function (e) {
e.preventDefault();
$.ajax({ 
        url: '/final/my.php',
        dataType : 'json',
        type: 'post',
         data: $(this).serialize(),
        timeout: 5000,
        success: function(data) {
        // I don't have what to add here to recieve that $arr JSON object from my.php page  

        },

        error: function(data) {
        alert('An error occurred');
        }
});
});

0 个答案:

没有答案
相关问题