Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

jQuery Ajax simple call

I'm trying a basic ajax call. So I'm hosting the following test php on a test server: http://voicebunny.comeze.com/index.php?numberOfWords=10 This web page is my own test that is already integrated to the VoiceBunny API http://voicebunny.com/developers.

Now I need to get the data printed by that web page in some other web page using jQuery. As you can see the web page echo's some JSON. How can I get this JSON from another web page?

This is the code I have:

 $.ajax({

        'url' : 'http://voicebunny.comeze.com/index.php',
        'type' : 'GET',
        'data' : {
            'numberOfWords' : 10
        },
        'success' : function(data) {              
            alert('Data: '+data);
        },
        'error' : function(request,error)
        {
            alert("Request: "+JSON.stringify(request));
        }
    });

I have tried many other variations but I always get an error and never the JSON. Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

please set the value of dataType property to json in the settings parameter of your ajax call and give it another try!

another point is you are using ajax call setup setting properties as string and it is wrong as reference site

$.ajax({

    url : 'http://voicebunny.comeze.com/index.php',
    type : 'GET',
    data : {
        'numberOfWords' : 10
    },
    dataType:'json',
    success : function(data) {              
        alert('Data: '+data);
    },
    error : function(request,error)
    {
        alert("Request: "+JSON.stringify(request));
    }
});

I hope this is helpful!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...