[英]Reading a json response in jquery
i am trying to reading json response from server by using jquery in webpage, this is my json response {"code":0,"message":success"}
, and this is my jquery code . this code does not sent data to server and does not read json response from server. please help me to resolve the problem. 我试图通过使用网页中的jquery从服务器读取json响应,这是我的json响应
{"code":0,"message":success"}
,这是我的jquery代码。此代码未将数据发送到服务器并且无法读取服务器的json响应。请帮助我解决问题。
$("#myForm").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
userid=$form.find(input[name="userid"]).val(),
file = $form.find( 'input[name="file"]' ).val(),
filename = $form.find( 'input[name="filename"]' ).val(),
url = $form.attr( 'action' );
/* Send the data using post */
var posting = $.post( url, { userid: userid,file:file,filename:filename } );
/* Put the results in a div */var obj = jQuery.parseJSON( '{ "code": "0" }' );
$.getJSON(url, { get_param: 'code' }, function(data) {
$.each(data, function(index, element) {
$('body').append($('<div>', {
text: element.name
}));
});
});
});
You have syntax error, in the find method quotes is missing :) 您有语法错误,在find方法中缺少引号:)
userid=$form.find(input[name="userid"]).val(),
cange to 可以
userid=$form.find('input[name="userid"]').val(),
PS: All browser have a javascript console, that show u where is script crashed PS:所有浏览器都有一个JavaScript控制台,向您显示脚本崩溃的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.