无法发布ajax请求

时间:2017-07-30 13:33:40

标签: jquery ajax

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  
<div class="window window1">
    <div class="header">header</div>
    <div class="content">content</div>
</div>

<div class="window window2">
    <div class="header">header</div>
    <div class="content">content</div>
</div>

<div class="window window3">
    <div class="header">header</div>
    <div class="content">content</div>
</div>

这是我发布一些表单数据的代码,但是我的控制台中出现了以下错误:

 $.ajax({
        type        : 'POST', // define the type of HTTP verb we want to use (POST for our form)
        contentType : 'json',
        beforeSend  : function(request){
            request.setRequestHeader("Access-Control-Allow-Origin","*");
        },
        url         : 'https://fedgis.com/NAGMapService/NAGMapService.aspx', // the url where we want to POST
        data        : school, // our data object
        dataType    : 'jsonp', // what type of data do we expect back from the server
                    encode          : true

    })

我无法弄清楚原因。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

问题在于您的school变量。 jQuery选择器缺少内部引用。例如:

$('input[name=type]').val()

实际应该是

$("input[name='type']").val()

等等。第一种语法不是jQuery库识别的正确语法。