Hmm.. can't get IMWS.get call to work..

Started by Jingo, June 18, 2019, 11:28:10 PM

Previous topic - Next topic

Jingo

Hi Mario - hoping you can solve a minor mystery for me.  The attached program is part of the SearchDB app I recently posted.  I am trying to generate a dropdown list of attributes so I am retrieving a list of them with a user provided pattern.  The app seems to crash and reload whenever I hit the button to load the fields...  but only when run within this app.  pulling out the same code into a new app with just a button and input field for pattern works as expected.  Any thoughts?

$('#btn-find').click(function(e) {
 
   var taggerS = $('#tag-pattern').val();
        if ($('#tag-pattern').val() != '') {
console.log("made it inside: " + taggerS);          <--- I get here with proper pattern
            IMWS.get('v1/metadata/tags',{
                pattern: taggerS,
                grouppattern: 'XMP',
                searchkey: true
            }).then(function(response) {

console.log("results: " + JSON.stringify(response.tags, null, 2));

            }, function(error) {
            console.log ("we erred: "+JSON.stringify(error, null, 2));           <--- I get this error and then the app reloads like it crashed or something
        })
        }
});



Mario

Do you use this button in a form perhaps?
Does the page reload whenever you press the button?
Do you use plain HTML and jQuery?

Try to call

e.preventDefault()

in your function so the browser does not submit your form (causing the page to reload).
Or use

return false

which serves the same purpose.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Thanks Mario.. the button isn't used in a form.. but the e.preventDefault() worked nontheless and now I have my data.  Thank you... would never have figured that one out!

Mario

Make sure you don't use a submit button or anything that may cause the browser to reload the page.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook