开发者

XML error in JavaScript file

开发者 https://www.devze.com 2022-12-11 23:30 出处:网络
When I execute this JavaScript file in Firefox; <script type=\"text/javascript\" > $(function () {

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: d开发者_JS百科ataString,
                        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?


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.


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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消