I am trying to get data from a json array that is populated by a php file. The data passes successfully to the php file, but it returns errors. I tried to inspect the page, it shows the returned arrays in the network element as shown in the picture Network inspection element , but the ajax success function won't work. If the data were passed successfully from the php file, why isn't execute the ajax successful function?
This is my ajax code:
var a = $(this).attr('idq');
$.ajax({
type: "POST",
url: "try.php",
data: {
queryy: a
},
dataType: "json",
success: function(result) {
var data = jQuery.parseJSON(result);
$.each(data, function(index, value) {
alert("successful");
});
},
error: function(result) {
alert("error");
}
});
If you give the dataType
as json
, then no need for parseJSON
. Just remove the jQuery.parseJSON()
from your code.
dataType:"json"
tells jQuery to parse the response as JSON.
Therefore, you're passing an actual object to jQuery.parseJSON
, which won't work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.