我如何将json发送到服务器?

时间:2021-09-09 19:34:57
$("#txt").click(function(){
var newTextBoxDiv = $(document.createElement('div'))
         .attr("id", 'TextBoxDiv' + inputs.length);

    newTextBoxDiv.after().html(
          '<input type="text" name="textbox' + i + 
          '" id="textbox' + inputs.length + '" value="" >' + '<input type="button" id="button'+inputs.length +'"value="x">');

    newTextBoxDiv.appendTo("#holder");

 inputs.push(['text','textbox'+i,'textboxtx'+i]);

    i++;
var jsonString = JSON.stringify (inputs);

     });

send json array to server how can i send inputs[] to local server wamp to be read by a controller written in symfony

将json数组发送到服务器如何将输入[]发送到本地服务器wamp,以便用symfony编写的控制器读取

<input type="button" id="txt" value="Add TextBox" style="" /><br>

1 个解决方案

#1


You can use the following $.ajax example

您可以使用以下$ .ajax示例

 $.ajax({
   url: url,
   type: 'POST',
   contentType:'application/json',
   data: JSON.stringify(data),
   dataType:'json'
});

The key part is contentType: 'application/json' to make sure the server receive as json and not other type

关键部分是contentType:'application / json',以确保服务器接收为json而不是其他类型

#1


You can use the following $.ajax example

您可以使用以下$ .ajax示例

 $.ajax({
   url: url,
   type: 'POST',
   contentType:'application/json',
   data: JSON.stringify(data),
   dataType:'json'
});

The key part is contentType: 'application/json' to make sure the server receive as json and not other type

关键部分是contentType:'application / json',以确保服务器接收为json而不是其他类型