Vito
Vito

Reputation: 1201

ajax method and SyntaxError : Unexpected token ":"

I'm in trouble with a simple script. I need to parse some xml response from a webservice

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">

    function callws() {
        $.ajax(function(){
                type:"GET",
                contentType: 'text/xml',
                dataType:"xml",
                url:"http://thewebservice/service.action?my=parameter",
                timeout:4000,
                async:false,
                success: parseXml,         
                error: function(jqXHR, textStatus, errorThrown){
                    alert(jqXHR.textStatus);
                    }
                }); // ajax

        function parseXml(xml) {
            $(xml).find("result").each(function(){
                $("#risposta").append($(this).find("row").text() + "<br />");
                });//each
           } //function parse
    } // termine callws

I don't understand why nothing work! I've only an error log from Chrome console SyntaxError : Unexpected token ":" at line 12 (contentType: 'text/xml',) I try to use other parameters but all the rows below the first (type:"GET") seems wrong... imho the syntax is ok in all of the script!

Advices?

Vito

Upvotes: 0

Views: 1234

Answers (2)

Sushanth --
Sushanth --

Reputation: 55740

$.ajax(function(){

supposed to be

$.ajax({

Upvotes: 1

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

I think you have the ajax syntax wrong. The first parameter is a regular ole' object, not a function. Try this:

function callws() {
        $.ajax({
                type:"GET",
                contentType: 'text/xml',
                dataType:"xml",
                url:"http://thewebservice/service.action?my=parameter",
                timeout:4000,
                async:false,
                success: parseXml,         
                error: function(jqXHR, textStatus, errorThrown){
                    alert(jqXHR.textStatus);
                    }
                }); // ajax
 // termine callws

^ All I did was take out function()

Upvotes: 4

Related Questions