PinoyStackOverflower
PinoyStackOverflower

Reputation: 5302

getting an error when fetching a json or xml data from a url using jquery-ajax

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! :)

Upvotes: 0

Views: 664

Answers (1)

Christopher Pelayo
Christopher Pelayo

Reputation: 802

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.

Upvotes: 2

Related Questions