0

I have this code:

jQuery(document).ready(function(){
        var user_key = "asdflk134";
        var app_key = "pigasdb95r91bva";
        var params = "app_key="+app_key+"&user_key="+user_key+"&format=xml";

        jQuery.ajax({
            type: "POST",
            url: "http://hellotxt.com/api/method/user.latest",
            data: params,
            dataType: "xml",
            success: function(data){
                jQuery(".result").html(data);
            }
        });
    });

When checking on my firebug console, I noticed this error:

XML Parsing Error: no element found Location: moz-nullprincipal:{3d9469e7-683c-41ea-9bd4-c761a0568b30} Line Number 1, Column 1:

^

What do you think is this error? I'm really stuck on this problem. Any help would be greatly appreciated and rewarded! Thanks! :)

6
  • Can you check the XHR sub tab under the Net tab in Firebug and show us the data in the response? I'm also curious why the data type is "text" in the Ajax call, when it seems like your trying to return XML (any reason why the data type isn't XML?) Commented Dec 27, 2011 at 7:48
  • Thanks for your reply. I changed the dataType into xml but still the same result. Here's the XHR from firebug: There's no response in the XHR. And in the XML Tab there's that error: XML Parsing Error: no element found Location: moz-nullprincipal:{0d5cfb18-8205-4631-bcd8-6b4aaffc3fe2} Line Number 1, Column 1: ^ Commented Dec 27, 2011 at 7:52
  • Did you try to go to that URL directly in your browser? I got valid XML that says <rsp status="FAIL"><message>app key not specified</message></rsp> Commented Dec 27, 2011 at 8:00
  • It might be due to Access-Control-Allow-Origin. Are you calling it from the same domain or your local server? Commented Dec 27, 2011 at 8:01
  • Yes, you got that error because you didn't specify an app_key, but if you'll use a form with an app_key in the field, you won't get that error. I'm not having a problem when I use an ordinary submit button, but when I use ajax, there's that problem arises wherein this error comes out XML Parsing Error: no element found Location: moz-nullprincipal:{0d5cfb18-8205-4631-bcd8-6b4aaffc3fe2} Line Number 1, Column 1: ^ Commented Dec 27, 2011 at 8:03

1 Answer 1

2

try to change the code that you have do it this way:

jQuery(document).ready(function(){
            var user_key = "asdflk134";
            var app_key = "pigasdb95r91bva";
            var params = "app_key="+app_key+"&user_key="+user_key+"&format=xml";

            jQuery.ajax({
                type: "POST",
                url: "http://hellotxt.com/api/method/user.latest",
                data: {
"user_key": user_key,
"app_key":app_key,
"format":"xml"},
                dataType: "xml",
                success: function(data){
                    jQuery(".result").html(data);
                }
            });
        });

you should submit an object to your data parameter for jquery to read it properly <key>:<value> the key will be taken as the parameter name.

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

3 Comments

Thanks Sir Chris! Miss you guys! ;) I better test it. ;)
no problem elson hope you could have sometime to visit our office again. ;)
Hahaha! you just changed the way I pass the variable into the url. Thanks anyway, very much appreciated! ;)

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.