简体   繁体   English

淘汰赛和AJAX发布请求PHP

[英]Knockout and AJAX post request PHP

I am attempting to get our knockout form to submit to a php script and am getting undefinedIndex errors. 我正在尝试获取我们的淘汰赛表单以提交到php脚本,并且遇到undefinedIndex错误。 I am pretty sure it is the way we are sending the data over in our ajax function. 我很确定这是我们在ajax函数中发送数据的方式。

Here is the ajax: 这是ajax:

        $.ajax({
        url: '/orders/add',
        type: 'post',
        data: {payload:ko.toJSON(allModel)},
        contentType: 'application/json',
        success: function (result) {
            alert(result);
        }
    });

Here is the PHP (we use laravel) 这是PHP(我们使用laravel)

 return json_decode($_POST["payload"]);

Pete is correct. 皮特是正确的。 You need to use just one data field. 您只需要使用一个数据字段。 If you want a variable, define it before the $.ajax post 如果需要变量,请在$ .ajax帖子之前定义它

var dataPayload = ko.toJSON(allModel);
$.ajax({
    url: '/orders/add',
    type: 'post',
    data: {payload: dataPayload},
    contentType: 'application/json',
    success: function (result) {
        alert(result);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM