如何将ajax结果对象从一个jquery函数传递到另一个

本文关键字:jquery 一个 函数 另一个 ajax 结果 对象 | 更新日期: 2023-09-27 18:09:15

我想把ajax成功结果对象从一个jquery函数传递给另一个。

下面是我的代码:
courses += '<a id="grid-item" class="dsd col-sm-6 col-md-4 " style="padding:10px; cursor:pointer" onclick="func("+result[i].subcourses+")" >';
我的jquery函数是:
function func(data)
  {
  }

却给我错误。结果[我]。Subcourses是对象类型

我怎样才能做到这一点…感谢任何帮助。提前感谢

完整代码:

  $.ajax({
            type: "GET",
            url: '@Url.Action("LoadCourse", "CourseMenu")',
            datatype: 'json',
            data: {
                idsubCoursecategory: Number(subcategoryid)
            },
            success: function (result) {

                if (result != null) {
                    if (result.length != 0) {
                        courses += '<h5 class="subcat-text">' + varsubcategoryname + '</h5>';
                        courses += "<div class='row' id='grid'>";
                        for (var i = 0; i <= result.length - 1; i++) {
                            var myid;
                            if (result[i].hassubcourse == false) {
                                courses += '<div id="grid-item" class="col-sm-6 col-md-4" style="padding:10px; cursor:pointer" onclick="fnLoadCourseMaster(''' + result[i].coursecode + ''', ' + divid + ', ''' + varcoursetypename + ''', ' + varcoursecategoryid + ', ''' + varcoursecategoryname + ''', ' + subcategoryid + ', ''' + varsubcategoryname + ''', ''' + result[i].coursename + ''')">';
                                courses += "<div class='thumbnail'>";
                                courses += "<img src='../../Images/dotnet4logo.jpg' alt='coursing' width='100px' height='100px'>";
                                // courses += "<hr /'>";
                                courses += "<div class='caption'>";
                                courses += "<h3 >" + result[i].coursename + "</h3>";
                                courses += '</div>';
                                courses += '</div>';
                                courses += '</div>';


                            }
                            else {
                                courses += '<a id="grid-item" class="dsd col-sm-6 col-md-4 " style="padding:10px; cursor:pointer" onclick="func()" >';
                                courses += "<div class='thumbnail'>";
                                courses += "<img src='../../Images/dotnet4logo.jpg' alt='coursing' width='100px' height='100px'>";
                                // courses += "<hr /'>";
                                courses += "<div class='caption'>";
                                courses += "<h3 >" + result[i].coursename + "</h3>";
                                courses += "<input type='hidden' value='" + result[i].subcourses + "'>";
                                courses += '</div>';
                                courses += '</div>';
                                courses += '</a>';

                            }

                        }
                        courses += '</div>';
                        $("#divCoursesEngine-" + divid).append(courses);
                    }
                    else {
                        noresultmsg += '<div class="alert alert-warning alert-dismissible" role="alert">';
                        noresultmsg += '<strong>Oops.!</strong> no result found for selected criteria.';
                        noresultmsg += '</div>';
                        $("#divCoursesEngine-" + divid).append(noresultmsg);
                    }
                }
                else {
                    alert("hi");
                }



            },
            error: function (xmlHttpRequest, textStatus, errorThrown) { alert('An error occurred while Data fetching.'); },
            complete: function () { }
        });

如何将ajax结果对象从一个jquery函数传递到另一个

你可以写结果价值= '"+ JSON.stringify([我].subcourses ) + "' ............如果你想要返回JSON,你可以将字符串转换为JSON.parse(value)。

如果你需要更多的帮助请告诉我