Passing jquery variable with json

前端 未结 2 1261
时光说笑
时光说笑 2021-01-25 02:55

I am trying to pass a jquery string to my cakephp controller but I keep getting an error saying json_decode expects a string but is passed an array.

Here is the code for

相关标签:
2条回答
  • 2021-01-25 03:19

    try this:

    var str = 'Data that i need';
    
    var jsonString = JSON.stringify(str);
    
    var DataToSend = {};
    DataToSend.data = JSON.stringify(jsonString);
    
    $.ajax({
        type: "POST",
        url: "http:/Configs/",
        cache: false,
        datatype: 'json',
        data: JSON.stringify(DataToSend),
        timeout: 100000,
    
        success: function(data) 
        {
            alert('Ok');
        }
    });
    
    0 讨论(0)
  • 2021-01-25 03:21

    Are you sure the url you use is correct? If you are using CakePHP, then why don't you work with $this->request->data?

    Try to debug your code with

    pr($_POST); exit;
    

    or

    pr($this->request); exit;
    

    What do they say?

    0 讨论(0)
提交回复
热议问题