DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Something wrong , sending post request using jquery.post()

133 Views Asked by oboualla At 27 September 2020 at 03:05 2025-12-10T00:57:24.370000

I have a file that's called camera.php, here is the source bellow :

camera.php

    <div id="video" style="margin: auto;text-align:center;">
            <video autoplay id="vid"></video>
    </div>
        <button id="start" class="btn" onclick="Start()">Start</button>
        <button id="stop" class="btn" onclick="Stop()">Stop</button>
        <button id="takeshot" class="btn" onclick="TakeShot()">TakeShot</button>
    <canvas id="canvas" width="640" height="480"></canvas>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
        video = document.getElementById('vid');

        function Start() {
            if (navigator.mediaDevices.getUserMedia) {
                navigator.mediaDevices.getUserMedia({video : true}).then((stream) => {
                    video.srcObject = stream;
                });
            }
            else
                console.log('ur navigator does not support getUserMedia !!');
        }

        function Stop() {
            if (video.srcObject)
                video.srcObject = undefined;
        }
        function TakeShot() {
            if (video.srcObject) {
                canvas = document.getElementById('canvas');
                gtc = canvas.getContext('2d');
                gtc.drawImage(video, 0, 0);
                imgData = canvas.toDataURL('image/png');
                //gtc.clearRect(0, 0, canvas.width, canvas.height);
                pb = document.getElementById('pb').value;
                pub(imgData, pb);
            }
            else
                console.log('you need to use Webcam to take a shot');
        }
        function pub(img, pb) {
          // using jquery.post() to send request
           $.post('https://xxxxxx.com/camera/save', {'img' : img, 'pub' : pb, 'stick' : stickSelectd}, (result) => {
                 obj = JSON.parse(result);
                 if (obj.error == true) {
                     document.getElementById('msg').innerHTML = obj.msg;
                 }
                 else
                     document.getElementById('msg').innerHTML = 'Publication has been added';
             }).done(() => {
                 alert('request is done');
             }).fail(() => {
                 alert('request is fail');
            });
         // using jquery.ajax() to send post request
            $.ajax({
                url : 'https://xxxxxx.com/camera/save',
                method : 'POST',
                data : {
                    'img' : img, 'pub' : pb, 'stick' : stickSelectd
                },
                headers : "Content-type : image/png",
                Success : (result) => {
                    alert(result);
                },
                err : () => {
                    alert('error');
                }
            });
        }
    </script>

.htaccess I know too many risks for allow-origin "*" but i use it just for testing.

Header Set Access-Control-Allow-Origin "*"

always request sending by $.post() alert 'request is fail' and sometimes the request is received from the server and save the image but the meme respond is getting ('request is fail').

there is all fine in my code or i miss something like headers, .. ?? and thanks for helping

ajax .htaccess request xmlhttprequest .post
Original Q&A
1

There are 1 best solutions below

0
oboualla oboualla On 27 September 2020 at 03:30

it works now with ajax(), i change the function pub to :

function pub(img, pb) {
            $.ajax({
                url : 'https://xxxxxxxx.com/camera/save',
                method : 'POST',
                data : {
                    'img' : img, 'pub' : pb, 'stick' : stickSelectd
                },
                headers : "Content-type : image/png"
            }).done((result) => {
                obj = JSON.parse(result);
                if (obj.error == true) {
                    document.getElementById('msg').innerHTML = obj.msg;
                }
                else
                    document.getElementById('msg').innerHTML = 'Publication has been added';
            }).fail(() => {
                document.getElementById('msg').innerHTML = 'something wrong !! try again';
            })
        }

i don't know why the old syntax doesn't work, I think it fine ?!

Related Questions in AJAX

  • Ajax jQuery firing multiple time display event for the same result
  • Implement Onfailure in webApi controller
  • AJAX PHP - Reload div after submit
  • ajax load data from mysql
  • Ajax-update only a component attribute, not the whole component nor its children
  • using ajax to get a php database result and then show the result in a button
  • How to prevent browser from executing some JavaScript when person clicks Back button?
  • ajax async: true statement execution order
  • Rails 4.2 jQuery loads only after refresh
  • WebForms GET Json requests (JsonRequestBehavior.AllowGet)
  • Rails - Ajax do not work properly on production server
  • Angular js Button click
  • Make jQuery/AJAX perform instantly on page load
  • jQuery Ajax Uncaught TypeError: Cannot use 'in' operator to search
  • Show success or error messages in Ajax response to Wordpress custom registration form

Related Questions in .HTACCESS

  • CodeIgniter + XDebug: debug only working in the main controller, index() function
  • About HTTP_HOST & PHP_SELF
  • .htaccess redirect 403 error files to 404 error document
  • RestApi server code is not workinng
  • Missing images after I redirect to a subdirectory using route.php and/or .htaccess in CodeIgniter Framework
  • Internal 500 server error: .htaccess: RewriteCond: bad flag delimiters
  • Error 404 not going after Wordpress Permalink change to custom structure
  • How work with parked domain names in Codeigniter?
  • Redirect keystone app to sub directory using htaccess
  • .htaccess rewrite condition to remove 'www' from 'https://www'
  • Change displayed URL using htaccess
  • .htaccess file making new domain redirect to my original domain
  • htaccess www to non-www for subfolders
  • htaccess redirect url with multiple folder
  • Url friendly htaccess PHP

Related Questions in REQUEST

  • Why does PHP add "\r\n" to an empty string?
  • Superagent share session / cookie info with actual browser
  • Check if POST is succesfull (Android)
  • Python Web Scraping title in a special div & Page 1 + 15
  • Pipe not working
  • post request (with body) in node.js
  • How do you Request[""] with a Dynamic Variable? Request["@Variable"]?
  • No schema supplied and other errors with using requests.get()
  • Send rest request after async responses volley
  • Download The Images By Node(request)
  • Get reponse message in Node using Request library?
  • Android Java Http Request Post
  • Can npm request module be used in a .pipe() stream?
  • { [Error: socket hang up] code: 'ECONNRESET' }
  • Spring MVC request

Related Questions in XMLHTTPREQUEST

  • XHR progress event microtask queue
  • Multiple HTTP post requests to a web service from XML files
  • When Promisifying a XMLHttpRequest, how to catch a throw Error
  • Angular http interceptor responseError doesn't have statusText
  • Make use of unnamed array
  • XHR from another domain to a https server
  • Multithreading for making http post requests to web service
  • Post and get in the same script (HTTP request)
  • jQuery Ajax: set dataUrl beforeSend
  • HTTP Post Request to web service . ERROR : Index was outside the bounds of the array
  • jQuery ajax "error", status 0, no response text, but tamper data shows it was a successful response 200?
  • XMLHttprequest not working the twitch.tv api
  • XMLHttpRequest cannot load file:///myfilepath/www/aws-sdk?=xxxxxxxxxx
  • write a parsed response from a json file in a div
  • What is the type of XMLHttpRequest in JavaScript?

Related Questions in .POST

  • jQuery .post is working but triggering .fail without any information
  • An issue with context on jquery waypoints post
  • Make jQuery Wait For $.post to complete updating page
  • Filtering/ using selectors on AJAX response
  • How to have default loading favicon come out on jquery .post
  • Saving data into database using $.post returns Internal server error
  • JQuery trying to take the focus out of the text input fields by a scan
  • How to pass HTML form array with jquery .post
  • Something wrong , sending post request using jquery.post()
  • jQuery .on not recognising urls from jQuery $.post
  • jQuery .each() and jQuery .post()
  • Colorbox with .post() request
  • jQuery post and dialog box
  • Passing a form field to ajax, and then posting it via php
  • JSON.parse unexpected character error encountered

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Math
  • Aftereffectstemplates