Send array with ajax request to php

前端 未结 5 863
逝去的感伤
逝去的感伤 2021-02-08 03:37

I created array like this [\"9\", \"ques_5\", \"19\", \"ques_4\"]. Now I want to send it from JS to PHP but I\'m not getting proper results. My JS code is:

5条回答
  •  渐次进展
    2021-02-08 04:30

    You can send the array in json format to the php and then use json_decode function to get back the array like

    In ajax call you have to send json for that you need to first make array of the values so that you get it in right form so that you json look like {"ques_5":"9","ques_4":19}

    and use in ajax call

     data: JSON.stringify(`your created json`),
     contentType: "application/json; charset=utf-8",
     dataType: "json",
    

    IN PHP it look like

    
    

提交回复
热议问题