$("#nonjstest").click(function() {
$.ajax({
url:"https://petstore.swagger.io/v2/pet/findByStatus?status=sold",
type: "GET",
contentType:"application/json",
success: function(data){
alert(data[0].id)
}
})
})
Here, I am passing the required parameters directly in the URL status=sold.
I want to pass them via a variable instead, but it's not working. I've tried the following:
var requiredata = ["status=sold"]
$("#nonjstest").click(function() {
$.ajax({
url:"https://petstore.swagger.io/v2/pet/findByStatus",
type: "GET",
data: requiredata,
contentType:"application/json",
success: function(data){
alert(data[0].id)
}
})
})
The request itself is successful, but nothing is returned, meaning, the parameters are not passed correctly. What is the problem with the way I'm passing the Array string?
I've tried stringifying the data, but it didn't work either.
Why is it not working? How do I pass the array string data with a variable?