Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 412 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to connect with mysql database using ajax and php for phonegap?

#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.
Reply

#2
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.
Reply

#3
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
Reply

#4
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.
Reply

#5
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
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through