0
var eweb_ip = "<% GetSetting("ip_address"); %>";    
var eweb_write = "http://" + eweb_ip + "/rokform/WriteLogixTags";
var datastring = $("#contactForm").serialize();
$('form').on('submit', function(e) {
    alert("inside submit function");
    e.preventDefault();
    alert("prevented default");
    $.ajax({
        type: 'post',
        url: eweb_write,
        data: datastring,
        dataType: "html",
        success: function() {
            alert('form was submitted');
        },
        error: function() {
            alert('error handing here');
        }
    });

});

This is displaying the success alert box but no change is being written to the server.

Martin Samson
  • 3,710
  • 19
  • 25
Brandon
  • 1
  • 1
  • 3

3 Answers3

0

Protip: use Google Chrome's (or Firefox) Network tab and select XHR to see if a request is being sent to the server and check the server's response.

enter image description here

AmuletxHeart
  • 411
  • 4
  • 16
  • It is telling me that form was submitted. Here is my logs from firebug. POST http://192.168.1.141/rokform/WriteLogixTags 302 redirect 1.25s | GET http://192.168.1.141/user/Web/Site/index-noReload.asp 200 OK 2.13s – Brandon Aug 15 '14 at 20:23
0

In case you are using JSP:

A scriptlet (what you wrote in your code) executes the java code written between the <% %>tags. You can write some logic in there.

If you want to use the java values in your JSP, what you need is a JSP expression, which you write between the <%= %>tags. Semi-colons are forbidden in there.

For example:

<%
    String eweb_ip = "192.168.1.1";  // JSP scriptlet
%>
...
<script type="text/javascript">
    var eweb_ip_js = "<%= eweb_ip %>"; // JSP expression
    ...
</script>

So for your problem, you can try this:

var eweb_ip = "<%= GetSetting('ip_address') %>";

For more informations, go to: http://docs.oracle.com/javaee/5/tutorial/doc/bnaou.html

BUT, if your form is correctly submitted and you still don't have what you want server-side, then you'll probably have to debug your server code. Your form may not contain what you want, so something like console.log(datastring); might help you with your problem.

Also, it might be only for the example that you did that, but $('form').on('submit', will apply on each form so it could be problematic later.

Thomas
  • 212
  • 1
  • 8
0

Brandon,

I have been working on the same problem today and happened to stumble upon your question. I too am trying to write data via an EWEB to a PLC without submitting a form and redirecting. Assuming an XMLHttpRequest based solution works for you, I've tested this code successfully:

function EWEBWrite(tagNameInp) {
    var formData = "numtags=1&t_1_slot=0&t_1_changed=1&t_1_value=1&t_1_tagname=" + tagNameInp + "&t_1_type=BOOL&t_1_display=Decimal";
    var srvWrt = new XMLHttpRequest();
    srvWrt.open("POST","/rokform/WriteLogixTags",false);
    srvWrt.send(formData);
    return
}

Keep in mind the EWEB has specific rules concerning what data type can be written to. I think at the very least they must all be atomic. If you look at the EWEB manual on the form submission method you should be able to get all the required data (type, display, etc). Let me know if you have any questions.