是否可以在ajax函数的url部分中将文本框的id作为url值传递?

时间:2017-04-15 11:29:21

标签: javascript ajax asp.net-ajax arcgis

这里我将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");
            }

        });

    }

1 个答案:

答案 0 :(得分:0)

你真的只是删除了引号,所以你正在使用你传入的参数:

url: data_spacial1

E.g:

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");
        }
    });
}