0

When I execute this JavaScript file in Firefox;

    <script type="text/javascript" >
        $(function () {
            $(".comsubmit").click(function () {
                var comsn = $("#comsn").val();
                var comrn = $("#comrn").val();
                var compic = $("#compic").val();
                var comment = $("#comment").val();
                var eventid = $("#eventid").val();
                var dataString = 'comsn=' + comsn + '&comrn=' + comrn + '&compic=' + compic + '&comment=' + comment + '&eventid=' + eventid;
                if (comment == '') {
                    alert('Must Type Comment to Post Comment');
                } else {
                    $("#flash").show();
                    $("#flash").fadeIn(400).html('<img src="assets/uploading.gif" />Loading Comment...');
                    $.ajax({
                        type: "POST",
                        url: "comments_post.php",
                        data: dataString,
                        cache: false,
                        success: function (html) {
                            $("ol#update").append(html);
                            $("ol#update li:last").fadeIn("slow");
                            $("#flash").hide();
                        }
                    });
                }
                return false;
            });
        });
    </script>

I get this error

Error: missing } in XML expression
Line: 31, Column: 2
Source Code:
}); }); 

The arrow points inbetween the first semi colon and the space.

What can I do to fix this error?

1
  • @Patrick: has general remark you should format your code properly it's far more easy to read and maintain. jsbeautifier.org you can use that for code not properly formated Commented Nov 18, 2009 at 6:59

3 Answers 3

3

Few remarks about your code:

  1. You don't need the cache: false option as you are performing a POST request.

  2. Instead of concatenating the parameters into dataString let jQuery handle formatting and escaping:

    $.ajax({
        type: "POST",
        url: "comments_post.php",
        data: { 
            comsn: comsn, 
            comrn: comrn, 
            compic: compic, 
            comment: comment, 
            eventid: eventid
        },
        success: function (html) {
            $("ol#update").append(html);
            $("ol#update li:last").fadeIn("slow");
            $("#flash").hide();
        }
    });
    
  3. Check the Content-Type header returned by comments_post.php. If it is not properly set (for example if it is set to text/xml), jQuery might try to parse the returned XML, while in reality you are returning HTML.

Sign up to request clarification or add additional context in comments.

Comments

2
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<font family="Arial" color="red" ><span style="font-size: x-small;"><script style="text/javascript" src="http://sites.google.com/site/attachanu/home/scrollingnew.js?attredirects=0&amp;d=1"> </script>
<script style="text/javascript"> 
var nMaxPosts = 20; 
var sBgColor; 
var nWidth; 
var nScrollDelay = 75; 
var sDirection="left"; 
var sOpenLinkLocation="N"; 
var sBulletChar="&#8226;"; 
</script> 
<script style="text/javascript" src="http://hackerz7.blogspot.com/feeds/posts/default?alt=json-in-script&amp;callback=RecentPostsScrollerv2"> 
</script></span></font>

Comments

0

I think the HTML you are passing from the Ajax call is not properly formated. Can you add an alert and make sure it looks OK?

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.