0

The following is in my file.js

function mainget(){
    $.ajax({    
          type: 'GET',
          url: 'example.php',
          data:json,
          success:function(data){
          }
    });       
} 

example.php

<?php 
     $con = mysqli_connect('address','DATBASE','pass','futureday');
     $result = mysql_query("SELECT * FROM $futureday");          
     $array = mysql_fetch_row($result);                             
     echo json_encode($array); 
?>

I have been struck with this for the past 2 days. I have tried inserting alert as first line of function mainget , which is successful, but after that I get nothing.

7
  • whats json? add alert(); into success: and debug it! Commented Feb 14, 2014 at 12:00
  • 2
    either use mysql or mysqli dont mix both . better to use mysqli. Commented Feb 14, 2014 at 12:00
  • What output are you getting is it ajax call or not? Commented Feb 14, 2014 at 12:08
  • post full mainget() to help u. and what is json ? is it data or datatype??? Commented Feb 14, 2014 at 12:23
  • I am trying the suggestions from all, I have changed the mysql to mysqli, thanks ghost. I have now changed data to dataType,Thanks to Sherin. That is the full mainget() Commented Feb 14, 2014 at 12:26

2 Answers 2

1

You are using data property in AJAX call to indicate the json data type. It is an invalid one. Use dataType to provide the data type. data property is used to pass the datas. And also put quotes to the values like:

dataType:'json'

Also change your example.php file. There you are using mysqli_connect to connect the database, then mysql_* to execute and fetch operations. It is not correct. Use either mysqli_* or mysql_*. Edit as:

<?php 
     $con = mysqli_connect('address','DATBASE','pass','futureday');
     $result = mysqli_query("SELECT * FROM $futureday");          
     $response  = array();
     while($array = mysqli_fetch_row($result)){
         $response[]=$array;
     }
     echo json_encode($response); 
?>
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, I did not downvote you. But I think the question has problems in both php and js side. Please try to add more info on this.
Then y don't the answer
I don't understand, you want to me to answer the question. I think user3240828 mixed mysqli and mysql statments, and ofcourse what you said on dataType:'json' is also one of the problem.
0

Use this

$mysqli = new mysqli('address','DATBASE','pass','futureday');
           $query = "SELECT * FROM $futureday";  
           $results=$mysqli->query($query) ;        
           $res=$mysqli->fetch_array(MYSQLI_ASSOC);
            echo json_encode($res);               

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.