Ok, I have been trying for months to get this to work. I even deleted my account and started over hoping the reinforcement would help, but I’m at a total loss. The random link works. I have tried forming my own api call, I’ve copy-pasta’d the work of others. Nothing will get it to work. I’m not even getting an error message. When I hit “Submit” the frame blinks, the text field clears, and I get no other response. Logging the apiCall variable gives me what I expect. Copying the result of that into the address bar gives me the JSON object I’m looking for. I’m ready to start kicking my children. (Not really.)
dataType: "json",
cache: false, // <-- Add this line
success: function (data) {console.log(data[0])},
Try this^^
I tried it on your pen and it’s working ( even if i’'m not sure why since it’s your first request which is not working )
EDIT:
Ah, found it (i think) ^^ You’re using an html form and submit the data with a submit button: as far as i can see the first submit action has no success so it’s default action is to return the same page, cached ( which prevent the data to be fetched). There’s a lot of assumption in here, waiting for someone else confirm or correct what i just said
Here a link on stack overflow where you can find your problem solved: error blinks when submit button is clicked
If you want, only if you want to, you can check out my code. I made it as simple as possible and you can check it as a reference.
Hi,
You can use $getJSON to do the API call. Based on your HTML structure, I will give you the simplest piece of code to do the job:
$( "form" ).submit( function( evt ){
// This avoids 'submitting' the form and stays on the same page.
evt.preventDefault( );
// Remember the 'var' keyword here.
var searchWord = $("#searchTerm").val();
var apiCall = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchWord + "&format=json&callback=?";
// This gets the JSON results from the URL stored in 'apiCall'.
$.getJSON( apiCall )
// If everything went well, we continue.
.done( function( results ) {
// Here it parses the JSON string and writes it into the div with the id="result" (#).
var json = JSON.parse( JSON.stringify( results ) );
$( '#result' ).text( json );
} );
// Here, after removing the previous semicolon, you could also check for failures:
// .fail( ... );
});
It works! Looks like warm feces, but it works! A little lipstick and this pig might do. Thanks folks.