1

I am working with a simple phonegap application. i need to display contents from mysql. i know that i cannot use php pages for phonegap. instead i use webservices in html to connect with mysql. My ajax webservice using responses is not working.

$.ajax({
    type:"GET",
    url:"config.php",
});

i have the database connection in my config.php file. But the connection to config.php is not at all established. Do i have to include any plugins for ajax or any jscript files. Please do help me.

4 Answers 4

1

lets say getdata.php has method to get data from db which includes config.php

$.ajax({
type:"GET",
url:"getdata.php",
dataType: "json",
data: { querystring1: querystringvalue},
success: function (data) {
if(data!=""){
parse json and do whatever you want on success
}else{

show some error when there was no data
}
});

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

0

Let's say you're trying to retrieve a list of cars, what you need to do is include your config.php in say, get_cars.php - and then this file will then return JSON of all the cars in your database when you make an AJAX request to it.

1 Comment

I think he knows that, but the Ajax call is not working. I've tried this myself and I didn't use any plugins. Guessing the error is in your jQuery script.
0

Assuming getdata.php is returning a JSONP object. This also assumes you are using JQuery.

$.getJSON("url/to/service?callback=?", function(result){
   //interact with result here
});

By denoting a callback you will avoid the issue of the browser blocking cross origin access.

This will allow for a separation of concerns. Your getdata.php can interact with the config.php server side for all database connections while the phonegap page will only have to use getdata.php to populate the page dynamically.

Comments

0

First check if the function where $.ajax({ type:"GET", url:"config.php", }); is kept is getting called or not, if it is then try echoing sumthing in config.php check ur console, the data being pass and the response coming, is it the same u want if so then the connection is establish.

After the connection to config.php is establish then go on and get what is done, now getting the data to the ajax function, you have to echo from config.php in json format which is more appropriate. You can use

.done(function(msg){ }

where msg is the content u echoed from config.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.