photools.com Community

IMatch Discussion Boards => IMatch Scripting and Apps => Topic started by: Jingo on June 18, 2019, 11:28:10 PM

Title: Hmm.. can't get IMWS.get call to work..
Post by: Jingo on June 18, 2019, 11:28:10 PM
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
        })
        }
});


Title: Re: Hmm.. can't get IMWS.get call to work..
Post by: Mario on June 19, 2019, 12:21:54 AM
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.
Title: Re: Hmm.. can't get IMWS.get call to work..
Post by: Jingo on June 19, 2019, 01:06:31 AM
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!
Title: Re: Hmm.. can't get IMWS.get call to work..
Post by: Mario on June 19, 2019, 08:56:03 AM
Make sure you don't use a submit button or anything that may cause the browser to reload the page.