• Resolved jetfighter

    (@jetfighter)


    Supposedly this is a very simple problem to solve with a few lines of code, but I don’t have the knowledge to get it done.

    I have a video upload button, and upon successfully uploading without any page refreshing, I receive a callback object named ‘uploadSuccess’ which contains several values including ‘hashed_id’. I need to grab that value (hashed_id) and insert it within a PUT (or POST, not sure) request like so:

    PUT https://api.wistia.com/v1/(insert hashed_id here)/.json?name=New-Name
    This will result in changing the name of the file to “New-Name”. How do I do this with AJAX? Using a POST method? I would so deeply appreciate it if you could provide an actual example with the proper syntax and structure! In desperate need of help here, as I am far outside my circle of competence.

    The following shows the general structure of the current upload script, which works perfectly BUT does not change the file name as I need it do.

    <div id="wistia-upload-widget" style="width: 250px; height: 40px;"></div>
    <script src="https://static.wistia.com/javascripts/upload_widget.js"></script>
    <script>
        var cback = {
            'uploadSuccess': function(jsonFile) {
                $("#form-submit").show();          //not important
            }
        };
        var widget1 = new wistia.UploadWidget({
    divId: 'wistia-upload-widget',                //not important
    publicProjectId: 'blahblahprojectid',         //not important
    callbacks: cback,
    buttonText: 'Upload Lesson Video' });         //not important
    </script>

    Maybe needs something like this in there? I’ve tried putting it under the ‘uploadSuccess’ code to no avail. Tried .post instead also:

    $.put("https://api.wistia.com/v1/medias/" + jsonFile.hashed_id + ".json?name=New-Name");

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi jetfighter,

    I am going to try to help you out here but providing exact syntax in Ajax would be difficult as there is no server setup (like yours) at my end that can help me replicate and code at my end. However, lets see what we can do here.

    Are you aware of debugging using dev tool either in firefox or chrome? I use chrome so what I would do in your case is add a break point on the line:

    $(“#form-submit”).show()

    Then in the console window I would look at what the variable “jsonFile” contains. If you are not aware how to do this have a look at this:
    https://www.html5rocks.com/en/tutorials/developertools/async-call-stack/

    Now if the jsonFile.hashid contains the expected value we are half way there. Next what I would do is a sanity check to make sure the API you are calling works fine. This would tell us wether the problem is in your code or the API. The documentation of wistia.com should tell you wether you should use POST or PUT. Do you have a reference to their developers documentation? Have you checked in there?

    Next if it is POST or PUT try externally using a chrome plugin like POSTMAN and see if it works from there. If it works from there then you it should also work from your code. Then you can decide wether to go for $.put() or $.post().

    Let me know how this works out.

    Just wanted to check if your question has been answered. We would love if it if you would mark this topic as resolved in the right hand sidebar. This helps our volunteers find the topics that still need attention and more people will get helped, possibly like you did.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Syntax for AJAX (json format)’ is closed to new replies.