是否可以在 AJAX 函数的 URL 部分中将文本框的 ID 作为 URL 的值传递



在这里,我将休息服务作为文本框的值传递arcgis提交值后如何使用服务url json结果成功?

  $("#submitp").click(function () {
       // alert('in');
        var data_spacial1 = $('#spacial1').val();
        alert(data_spacial1);
        getspacial1(data_spacial1);
    });
    function getspacial1(data_spacial1) {
        alert("in1");
        $.ajax({
            url: "data_spacial1",  // where data_spacial1=http://164.100.133.211:6080/arcgis/rest/services/SoilM/2016April18/MapServer/0?f=pjson
            data: { f: "json", where: "1=1", returnGeometry: false },
            dataType: "jsonp",
            jsonpCallback: "callback",
            success: function (response) {
                console.log("got response: ", response);
                alert("in2");
            }
        });
    }
实际上,

您只需删除引号,因此使用传入的参数:

url: data_spacial1

例如:

function getspacial1(data_spacial1) {
    alert("in1");
    $.ajax({
        url: data_spacial1, // ***
        data: { f: "json", where: "1=1", returnGeometry: false },
        dataType: "jsonp",
        jsonpCallback: "callback",
        success: function (response) {
            console.log("got response: ", response);
            alert("in2");
        }
    });
}

最新更新