Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax simple call

Tags:

jquery

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

like image 667
Alejandro Avatar asked Sep 25 '13 21:09

Alejandro


People also ask

How can make AJAX call in jQuery?

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.

Can I make AJAX requests by jQuery?

jQuery ajax() Method. The jQuery ajax() method provides core functionality of Ajax in jQuery. It sends asynchronous HTTP requests to the server.

What is the AJAX call?

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.

What is AJAX method in jQuery?

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.


1 Answers

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!

like image 127
Saeed Alizadeh Avatar answered Sep 23 '22 12:09

Saeed Alizadeh