Discussion:
JSON + variable
weidc
2010-02-03 12:44:35 UTC
Permalink
Hello,

well i got a problem with using JSON.

My code looks like this:

$(function()
{

$.ajax({
type:'GET',
url: url,
data:"format=json&id=123",
success:function(data) {
alert(data); // doesn't work
},
dataType:'jsonp'
});

});

The URL is an external one.
The answer looks something like this:

yasearch({"q":"uboot","f":["k"],"r":[["uboote"],["uboot chat"],["uboot
pc spiel"],["uboot simulation"],["modell uboot"],["uboot hamburg"],
["uboot museum"],["atom-uboot"],["uboot ping"],["rc uboot"]]})

I always get this error msg in firebug:
yasearch is not defined

I tried to define it in any way but it doesn't seem to work. I use
JSON for the first time now and don't know how to get an useable
answer.

I hope someone can help me.
rnivash
2010-02-03 16:25:29 UTC
Permalink
Hi mueller,

The response is look like a function call.

/*
yasearch(
{
"q": "uboot",
"f": ["k"],
"r": [["uboote"], ["uboot chat"], ["ubootpc spiel"], ["uboot
simulation"], ["modell uboot"], ["uboot hamburg"], ["uboot museum"],
["atom-uboot"], ["uboot ping"], ["rc uboot"]]
}
)

*/

try this,

function yasearch(a) {
alert(a.q);

}

$(function() {
$.ajax({
type: 'GET',
url: 'js.html',
data: "format=json&id=123",
success: function(data) {
eval(data);
},
dataType: 'json'
});
});
Post by weidc
Hello,
well i got a problem with using JSON.
$(function()
{
        $.ajax({
                type:'GET',
                url: url,
                data:"format=json&id=123",
                success:function(data) {
                        alert(data); // doesn't work
                },
                dataType:'jsonp'
        });
});
The URL is an external one.
yasearch({"q":"uboot","f":["k"],"r":[["uboote"],["uboot chat"],["uboot
pc spiel"],["uboot simulation"],["modell uboot"],["uboot hamburg"],
["uboot museum"],["atom-uboot"],["uboot ping"],["rc uboot"]]})
yasearch is not defined
I tried to define it in any way but it doesn't seem to work. I use
JSON for the first time now and don't know how to get an useable
answer.
I hope someone can help me.
weidc
2010-02-03 16:53:20 UTC
Permalink
Well, wow thats nice! Thanks for your answer.
Really awesome, I get an answer!

But I have to use dataType: 'jsonp'. If I use dataType: 'json' the
alert doesn't work.

Oh my god it was so simple and I was thinking about it a million
hours, thank you a lot.
Post by rnivash
Hi mueller,
The response is look like a function call.
/*
yasearch(
        {
        "q": "uboot",
        "f": ["k"],
        "r": [["uboote"], ["uboot chat"], ["ubootpc spiel"], ["uboot
simulation"], ["modell uboot"], ["uboot hamburg"], ["uboot museum"],
["atom-uboot"], ["uboot ping"], ["rc uboot"]]
        }
        )
*/
try this,
function yasearch(a) {
            alert(a.q);
}
        $(function() {
            $.ajax({
                type: 'GET',
                url: 'js.html',
                data: "format=json&id=123",
                success: function(data) {
                    eval(data);
                },
                dataType: 'json'
            });
        });
Post by weidc
Hello,
well i got a problem with using JSON.
$(function()
{
        $.ajax({
                type:'GET',
                url: url,
                data:"format=json&id=123",
                success:function(data) {
                        alert(data); // doesn't work
                },
                dataType:'jsonp'
        });
});
The URL is an external one.
yasearch({"q":"uboot","f":["k"],"r":[["uboote"],["uboot chat"],["uboot
pc spiel"],["uboot simulation"],["modell uboot"],["uboot hamburg"],
["uboot museum"],["atom-uboot"],["uboot ping"],["rc uboot"]]})
yasearch is not defined
I tried to define it in any way but it doesn't seem to work. I use
JSON for the first time now and don't know how to get an useable
answer.
I hope someone can help me.
Loading...