How to tell whether AJAX give JSON response not a html page in php?

Recommended Answers

All 2 Replies

What do you mean? Can you post code?

if you want ajax to send json you need to tell ajax function to send json, if you want php to send json you tell php json_encode(); or you can use json_decode();

with jquery its pretty easy.

var data = 'object':{'key'=>'value', 'key2' => 'value2'}; // Create json object

url: '', // url to php script
type: "POST", //Send post method to php
dataType: "json"; // return json from php script
data: data, // Post data
success: function(data){

Member Avatar

Well I would imagine that if you're doing an ajax call on your own pages, you'd know anyway? Are you doing x-domain calls e.g. with jsonp?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.