Note that there are some explanatory texts on larger screens.

plurals
  1. POPosting Data from textBox in HTML to Restful Service using jQuery AJAX
    primarykey
    data
    text
    <p>I am trying to post data from input values from textBoxes to restful service via jQuery and ajax. But im unable to do it. </p> <p>Here is my HTML code:</p> <pre><code>&lt;!DOCTYPE html&gt; &amp;nbsp; &lt;html&gt; &lt;head&gt; &lt;title&gt;Login Page&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="LoginHtml.js"&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="registration"&gt; &lt;h2&gt;Login Account&lt;/h2&gt; &lt;form id="registerUserForm"&gt; &lt;fieldset&gt; &lt;p&gt; &lt;input id="txtUserName" type="text" required="required" autofocus="true" placeholder="User Name" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input id="txtPassword" type="password" required="required" placeholder="Password" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="button" id="submitForm" autofocus="true" /&gt;&lt;br&gt; &lt;input type="button" value="Login" onclick="Call()" &gt;&lt;/input&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is my javascript code:</p> <pre><code>function Call() { jQuery.support.cors = true; var data = {}; data.uid = document.getElementById('txtUserName'); data.pwd = document.getElementById('txtPassword'); $.ajax({ data: jQuery.toJSON(data), dataType: "json", url: "http://:xxxxxx:8080/Service1/Login", type: "GET", contentType: "application/json; charset=utf-8", success: function (result) {alert("success"); alert(result.d);} error: function OnError(request, result, error) { alert(result); } }); </code></pre> <p>Here is my code for service:</p> <pre><code> [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public UserProfile Login(string uid, string pwd) { UserProfile oUser = null; //UserDao userDao; using (UserProfileDataContext db = new UserProfileDataContext()) { var u = db.Users.FirstOrDefault(o =&gt; o.Username == uid &amp;&amp; o.Password == pwd); if (u != null) { oUser = new UserProfile(); oUser.Id = u.Id; oUser.Username = u.Username; oUser.Password = u.Password; oUser.Email = u.Email; } } return oUser; } </code></pre> <p>Tell me where I am wrong.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload