0

I am doing on ajax call to controller from view in which i am getting an error javascript run time error :function expected.

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. pls help me with this.

2 Answers 2

3

Try $.ajax({ instead of $.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()();

http://jsfiddle.net/NsmB7/

However, you can't do this:

$.ajax()();

because $.ajax() doesn't return a function, it returns a jqXHR object. You just want to execute $.ajax and pass your config object as a parameter:

$.ajax({...});
Sign up to request clarification or add additional context in comments.

2 Comments

Great it works .. simple but i think i need more understanding in scripting thank u jason p
@user3534449 I added a bit more explanation.
0

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] )

url: (String) The URL of the page to load.

data (Optional): (Map) Key/value pairs that will be sent to the server.

callback (Optional): (Function) A function to be executed whenever the data is loaded successfully.

type (Optional): (String) Type of data to be returned to callback function: “xml”, “html”, “script”, “json”, “jsonp”, or “text”.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.