How to return an array from an AJAX call?

前端 未结 6 1404
猫巷女王i
猫巷女王i 2020-12-02 06:13

I\'m searching for a better solution to making an AJAX call with jQuery, having the PHP file return an array, and have it come out client-side as a Javascript array. Here is

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 07:10

    well, I know that I'm a bit too late, but I tried all of your solutions and with no success! So here is how I managed to do it. First of all, I'm working on an Asp.Net MVC project. The Only thing I changed was in my c# method getInvitation:

    public ActionResult getInvitation (Guid s_ID)
    {
        using (var db = new cRM_Verband_BWEntities())
        {
            var listSidsMit = (from data in db.TERMINEINLADUNGEN where data.RECID_KOMMUNIKATIONEN == s_ID select data.RECID_MITARBEITER.ToString()).ToArray();
            return Json(listSidsMit);
        }
    }
    

    SuccessFunction in JS :

    function successFunction(result) {
        console.log(result);
    }
    

    I changed the Method Type from string[] to ActionResult and of course at the end I wrapped my array listSidsMit with the Json method.

提交回复
热议问题