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
The ajax() method in jQuery is used to perform an AJAX request or asynchronous HTTP request. Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.
jQuery ajax() Method. The jQuery ajax() method provides core functionality of Ajax in jQuery. It sends asynchronous HTTP requests to the server.
AJAX calls are one method to load personalized content separately from the rest of the HTML document, which allows for the full HTML document to be cached, improving back end load time.
jQuery ajax() Method The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With