3

I am doing this for the first time. i want a data of another HTML page using AJAX call and jQuery in HTML page. Below is mycode

this is my .js code

<script type="text/javascript">
$(document).ready(function()
{
    $('#submit').click(function(){
        var name =$('#name').val();
        var pass =$('#passsword').val();
        if(name=='' || pass==''){
            alert('first fill the details');
        }
        else {
            $.ajax({
                    method:'POST',
                    url:"login.html",
                    data:{name:name,
                    password:pass},
                    daatType:"HTML",
                    success:function(status) {
                            alert('success');
                            $('#div').html(status);
                        } 
                })

        }

    })
})

this is my Html code

<form>
   <label>Name:</label><input type="text" id="name"><br>
   <label>Password:</label><input type="text" id="password"><br>
   <button type="submit" id="submit" >Submit</button>
</form>
<h2 id="div"></h2>

please help

XYZ
  • 4,450
  • 2
  • 15
  • 31
  • there might be a typo in your jQuery code: `daatType` instead if `dataType` I guess – joH1 May 17 '17 at 10:02
  • What is the value of the status variable? You could take data to next page using a url parameter. For eg if the next page is www.abc.com/def.html, Then you can do www.abc.com/def.html#This is data. In the new html page you can get this value using javascript : var x = location.hash; – Max08 May 17 '17 at 10:07
  • Please clear whether your data is short or long ? If it is short and not sensitive you can pass in URL like this. window.location.href = site_url + 'status/' + data; do it in your success function. – Rahul Chauhan May 17 '17 at 10:11

1 Answers1

2

Change dataType:"HTML" to dataType:"json"

dataType:'json' // its mean server return type data

whereas

contentType:'json' // send data type to server should be json
vatz88
  • 2,422
  • 2
  • 14
  • 25