0

i have a problem.I am waiting for your help.Thank you

index codes are here.Even if i write dataType:JSON it didn't work.

index.php

function referansButon(sayfaNo)
       {
           $.ajax({
           url:"ajax.php",
           type:"POST",
                                   
           data:"action=referansButon&referansSayfano="+sayfaNo,
           success:function(data)
           {
               var result=$.parseJSON(data);
               alert(result[0]);
              alert(result["referanslar"]); // i know they are the same but i just wanted to see it if it 
                                          //is working
           }
                   
         });
      }

ajax.php

$referanslar="sdfdsfds";
$sayfalar= "sdfsdfdsfds";   //just for trying values.
$array=array("referanslar"=>$referanslar,"sayfalar"=>$sayfalar);
echo json_encode($array);
9
  • What is returning any thing or just null Commented Nov 13, 2020 at 15:11
  • data variable is full but result variable is empty Commented Nov 13, 2020 at 15:18
  • Your getting values with wrong ways Commented Nov 13, 2020 at 15:22
  • And what kind of value is data? Commented Nov 13, 2020 at 15:24
  • clear your self with the answer below Commented Nov 13, 2020 at 15:24

1 Answer 1

2

data is a string which is returning from $.ajax you convert the string to json and store in var result and after that you are using data again which is still string. update your code

var result=$.parseJSON(data);

and for first obj

alert(result.referanslar);

And for second obj

alert(result.sayfalar);

instead of [0] & [1]

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

1 Comment

json could not be converted to string , i did what you trying to say but its same

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.