doedje / jquery.soap

This script uses $.ajax to send a SOAP:Envelope. It can take XML DOM, XML string or JSON as input and the response can be returned as either XML DOM, XML string or JSON too.
352 stars 148 forks source link

Calling “$.soap” with React.js #131

Closed Aspro1 closed 5 years ago

Aspro1 commented 5 years ago

I would like to call a SOAP webservice with React.js. I installed jquery.soap (version 1.7.3) with npm in the “node_modules” folder. I tried using this code in my “App.js” file:

` $.soap({ url: 'http://localhost:…/LoginService.asmx', // with a port number method: 'Login',

    data: {
        name: this.state.userName,
        password: this.state.password
    },

    success: function (soapResponse) {
        // do stuff with soapResponse
        // if you want to have the response as JSON use soapResponse.toJSON();
        // or soapResponse.toString() to get XML string
        // or soapResponse.toXML() to get XML DOM
    },
    error: function (SOAPResponse) {
        // show error
    }
});

` I have this error message:

––––– Failed to compile ./src/App.js Line 43: '$' is not defined no-undef Line 61: 'soapResponse' is not defined no-undef

Search for the keywords to learn more about each error. This error occurred during the build time and cannot be dismissed. –––––

What is wrong? Do I need to add an import at the beginning of my “App.js” file? If so, I cannot find out what the import must look like. The “README.md” file does not say anything about it.

doedje commented 5 years ago

As mentioned in the readme: https://github.com/doedje/jquery.soap/blob/master/README.md#dependencies

jQuery.soap is a jQuery plug-in and as such it needs jQuery. I admin the readme is not overly clear on this....

Aspro1 commented 5 years ago

The “README.md” file mentions it generally, but I would have appreciated being able to save some time by finding more accurate information like this in the “README.md” file or in a reply to my issue:

––––– In a “*.js” file using React.js, add these imports at the beginning:

import 'jquery';
import 'jquery.soap';

Initialization lines need to be used prior to a “$.soap” call:

    let $ = require('jquery');
    require('jquery.soap');
    $.soap({
        …
    });

–––––

doedje commented 5 years ago

Sorry Astro, there are numerous platforms and libraries and ways to use JavaScript and I really think it is way out of the scope of my readme to tell you how to include dependencies for every single one of them. I tell you the dependencies, you read the documentation of whatever platform or library your using to come up with the proper code to include them... that’s called self reliance and is as far as I’m concerned a obligatory skill for anyone that wants to be a coder.