首页 > 解决方案 > 如何将来自 Ajax 的数据发布到另一个域?

问题描述

  $("body").on("click", "#btnAdd", function () {
        //Loop through the Table rows and build a JSON array.
        var students = new Array();
        debugger;
        $("#tblStdnt tbody tr").each(function () {
            var row = $(this);
            var student = {};
            student.Name = row.find("td").eq(1).html();
            student.Address = row.find("td").eq(2).html();
            student.Phone = row.find("td").eq(3).html();
            student.Email = row.find("td").eq(4).html();
            student.Adhar = row.find("td").eq(5).html();
            student.Qualificaton = row.find("td").eq(6).html();
            students.push(student);

        });
        var testdata = JSON.stringify(students);

        //Send the JSON array to Controller using AJAX.
        $.ajax({
            type: "POST",
            url: "http://orionerp.in/imps/post_enquiry.php",
            crossDomain: true,
            data: JSON.stringify(students),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                alert(r + students);
            },
            failure: function (msg) {
                alert(msg);
            },
            error: function (xhr, err) {
                alert(err);
            }
        });
    });

**错误是**

无法加载http://orionerp.in/imps/post_enquiry.php:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问源“ http://localhost:63315 ”。

标签: asp.net-ajax

解决方案


推荐阅读