简体   繁体   English

Javascript运行时错误:函数预期的ajax调用

[英]Javascript runtime error:function expected ajax call

I am doing on ajax call to controller from view in which i am getting an error javascript run time error :function expected. 我正在从视图中获取对控制器的ajax调用,在该视图中我遇到了错误javascript运行时错误:预期的功能。

here my script 这是我的剧本

<script type="text/javascript">

            var jsonData = [];
            var ms1 = $('#ms-tpl').magicSuggest({
                data: jsonData,
                sortOrder: 'name',
                maxResults: false
            });
            $('#Register').click(function () {
                debugger;
                var dataplus = ms1.getValue();
                var tagid = document.getElementById('TagId').value;
                var tagtitle = document.getElementById('TagTitle').value;
                var tagname = document.getElementById('TagContent').value;
                $.ajax()({
                    url: '@Url.Action("Post")' + '?tagid=' + tagid + '?tagtitle=' + tagtitle + '?tagname=' + tagname + '?dataplus=' + dataplus,
                    type: 'POST',
                    cache: false,
                    success: function (html) {
                        $('#bind').html(html);

                    }

                });
            });

            $('#click').click(function () {
                debugger;
                alert(ms1.getValue());

            });

    </script>    

Note: I am using MAgicSelect query to select multiple values. 注意:我正在使用MAgicSelect查询来选择多个值。 pls help me with this. 请帮助我。

Try $.ajax({ instead of $.ajax()({ . 尝试$.ajax({代替$.ajax()({

Consider this: 考虑一下:

function outerFunction() {
    var innerFunction = function() {
        alert('hi');
    };
    return innerFunction;
}

Since outerFunction actually returns a function, you could do what you were attempting: 由于outerFunction实际上返回一个函数,因此您可以尝试执行以下操作:

outerFunction()();

http://jsfiddle.net/NsmB7/ http://jsfiddle.net/NsmB7/

However, you can't do this: 但是,您不能这样做:

$.ajax()();

because $.ajax() doesn't return a function, it returns a jqXHR object. 因为$.ajax()不返回函数,所以它返回jqXHR对象。 You just want to execute $.ajax and pass your config object as a parameter: 您只想执行$.ajax并将配置对象作为参数传递:

$.ajax({...});

Use just like this: 像这样使用:

  $.ajax({

                url: '',
                contentType: "application/json;",
                dataType: "json",
                type: "POST",
                data: {  },
                success: function (data) {
                    alert(data);

                },
                error: function () {

                },
            });

jQuery.post( url, [data], [callback], [type] ) jQuery.post(url,[data],[callback],[type])

url: (String) The URL of the page to load. url:字符串)要加载的页面的URL。

data (Optional) : (Map) Key/value pairs that will be sent to the server. data (Optional) :(映射)将发送到服务器的键/值对。

callback (Optional): (Function) A function to be executed whenever the data is loaded successfully. callback (Optional):函数)每当成功加载数据时将执行的函数。

type (Optional): (String) Type of data to be returned to callback function: “xml”, “html”, “script”, “json”, “jsonp”, or “text”. type (Optional):字符串)要返回给回调函数的数据类型:“ xml”,“ html”,“ script”,“ json”,“ jsonp”或“ text”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM